How to Copy Attached Cover Image (cover.jpg) to a Video File for Encoding with FFmpeg?

Abstract: Embed a cover image as metadata in an MP4 file using FFmpeg without re-encoding the video or treating the image as a video stream.

Created: 2026-10-23 by
To attach a cover image to a video file using FFmpeg, you must use the -map directive to explicitly select only the video and audio streams from the source file, then map the image as an attachment. The command ffmpeg -i input.mp4 -i cover.jpg -map 0:v -map 0:a -map 1 -c copy -c:v libx264 -metadata:s:t:0 mimetype=image/jpeg output.mp4 ensures the image is stored as metadata rather than being decoded and re-encoded as a video track. This method preserves your original video quality while embedding the artwork for players that support it. Many users encounter issues when trying to embed cover art because they mistakenly treat the image as another video stream. If you simply concatenate inputs without explicit mapping, FFmpeg may interpret the JPEG or PNG as a sequence of frames, leading to corrupted output files or massive file sizes. Understanding how FFmpeg handles streams is crucial for successful media packaging. For deeper insights into common encoding pitfalls, you can review [FFMPEG Video Encoding Example Not Working](/news/1405572/ffmpeg-encoding-issue), which addresses similar structural errors in command construction.

Understanding Stream Mapping in FFmpeg

FFmpeg processes media files as collections of streams. A standard MP4 file contains video streams, audio streams, and potentially subtitle or data streams. When you introduce a second input file, such as a cover image, FFmpeg sees two distinct sources: Input 0 (the video) and Input 1 (the image). By default, if you do not specify which streams to include, FFmpeg might attempt to process all available streams from both inputs. This often results in the image being treated as a video track, which is not what you want for a static cover image. The -map option gives you precise control over this behavior. It tells FFmpeg exactly which streams from which inputs should be included in the output file. To embed a cover image, you need to map the video and audio streams from the first input (-map 0:v and -map 0:a) and then map the single stream from the second input (-map 1). This separation ensures that the video and audio are processed normally, while the image is handled as an attachment stream. Without this explicit mapping, you risk creating duplicate streams or corrupting the video container.

The Correct Command Structure

The core of the solution lies in constructing a command that separates the encoding of the video from the attachment of the image. Below is the robust command structure that avoids the common pitfalls of duplicate streams.
ffmpeg -i input_video.mp4 -i cover.jpg \
-map 0:v -map 0:a \
-map 1 \
-c copy \
-c:v libx264 \
-metadata:s:t:0 mimetype=image/jpeg \
output_with_cover.mp4
Let's break down each component of this command. The -i input_video.mp4 specifies your source video. The -i cover.jpg specifies the image file. The -map 0:v selects all video streams from the first input. The -map 0:a selects all audio streams from the first input. The -map 1 selects all streams from the second input, which is just the image. The -c copy flag tells FFmpeg to copy the selected video and audio streams without re-encoding them. This is critical for maintaining quality and speed. However, since we also have -c:v libx264, the video will actually be re-encoded with the H.264 codec. If you want to keep the original video bit-for-bit identical, remove -c:v libx264 so that -c copy applies to everything except the attachment. The -metadata:s:t:0 mimetype=image/jpeg tag informs compatible players that the attached stream is a JPEG image. The s:t:0 refers to stream type "t" (attachment) index 0. If you are experiencing issues with constant bitrate settings affecting your final output, ensure your encoding parameters align with your target platform requirements. You can find guidance on consistent encoding practices at [How to Convert FFmpeg Constant Bitrate for Consistent Video Encoding](/news/1400770/convert-ffmpeg-constant-bitrate).

Handling Different Image Formats

While JPEG is the most common format for cover art, FFmpeg supports other formats like PNG. If you are using a PNG file, you must change the mimetype metadata accordingly. Replace image/jpeg with image/png in the metadata command. Some players may prefer one format over the other due to compression efficiency or transparency support. PNG offers lossless compression and alpha channels, but it results in larger file sizes compared to JPEG. JPEG is generally preferred for cover art due to its smaller size and universal compatibility. When working with high-resolution images, ensure that the image dimensions are reasonable. Extremely large images can cause playback issues on some devices or media servers. A standard resolution of 1920x1080 pixels is usually sufficient for most modern displays. If your image is significantly larger, consider resizing it before attaching it to the video. This reduces the overall file size and improves compatibility.

Verifying the Attached Cover

After running the command, it is essential to verify that the cover image was successfully embedded. You can use ffprobe to inspect the metadata of the output file. Run the following command in your terminal:
ffprobe -show_streams output_with_cover.mp4
Look for a stream with codec_type=attachment. Inside this stream's information, you should see filename=cover.jpg and mimetype=image/jpeg. If these fields are present, the attachment was successful. If you do not see an attachment stream, check your -map arguments to ensure you correctly mapped the second input. Additionally, play the video in a player that supports embedded cover art, such as VLC or MPC-HC, to visually confirm the image appears during playback. Some advanced encoding scenarios, particularly those involving hardware acceleration or specific pixel formats, can complicate stream handling. If you are using NVENC or other hardware encoders, refer to [HEVC NVENC with ffmpeg: '-pix_fmt p010le' and '-pix_fmt yuv420p10le' doesn't work](/news/1172514/hevc-nvenc-ffmpeg-issue) for troubleshooting tips related to pixel format mismatches that might interfere with stream mapping.

Common Mistakes to Avoid

One frequent mistake is omitting the -map flags entirely. Without them, FFmpeg may auto-select streams, which can lead to unpredictable results, especially when dealing with multiple audio tracks or subtitles. Another error is using -c copy for the entire file when you intend to re-encode the video. This will prevent any video changes from taking effect. Always specify codecs for streams you want to modify. Additionally, some users try to attach the image by adding it as a subtitle track. While technically possible, this is not the standard method for cover art and may not be recognized by all media players. Using the attachment stream type is the correct approach for metadata-based artwork. Ensure that your output container format supports attachments. MP4 and MKV containers both support embedded attachments, but AVI does not. Choose your container wisely based on your distribution needs.

Frequently Asked Questions

Why is my video file size increasing after adding the cover?

The increase is minimal and comes solely from the size of the image file itself, plus the overhead of the metadata. If the size increase is significant, you likely re-encoded the video unnecessarily or used a very large image file. Check your command to ensure you are not duplicating video streams.

Can I add multiple cover images to one video?

Yes, you can map multiple images by adding additional -map commands for each input file. However, most media players will only display the first attachment stream they encounter. Use the -metadata:s:t:0 flag to designate which image is the primary cover art.

Does this method work for audio files like MP3 or FLAC?

Absolutely. The same principle applies to audio files. You map the audio stream from the source file and the image from the second input. The metadata mimetype should still be set to image/jpeg or image/png depending on your image format.

What if my player doesn't show the cover image?

Not all players support embedded cover art via attachment streams. Many older or lightweight players ignore this metadata. Try playing the file in a robust player like VLC or Kodi. If it still fails, the issue may be with the mimetype tag or the image format itself.

Is there a way to remove an existing cover image?

To remove an existing cover, you can remux the file without mapping the attachment stream. Use -map 0:v -map 0:a and exclude any -map commands targeting attachment streams. This creates a new file without the embedded image, effectively stripping it out.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More