Embedding a Thumbnail Image in MP4 with FFmpeg
With FFmpeg, you can read an image as an extra input after the video and add -disposition:v:1 attached_pic. This embeds a thumbnail image (cover image, cover art) into an MP4 without re-encoding the video. Use this when you want file listings and players to show a specific image as the video's thumbnail, instead of a frame from the middle of the video.
ffmpeg -i input.mp4 -i cover.jpg -map 0 -map 1 -c copy -disposition:v:1 attached_pic output.mp4
In my test environment, the embedded JPEG was stored in the MP4's cover image location (covr). When I extracted it, it was not a single byte different from the original file. If you forget attached_pic, the image is stored as a one-frame video track.
The test environment was Ubuntu 24.04.5 with FFmpeg 6.1.1 (Ubuntu package 6.1.1-3ubuntu5). I checked the embedded result with ffprobe, AtomicParsley (20210715.151551.e7ad03a-1), Python's mutagen 1.48.1, and my own script. I checked thumbnail display with ffmpegthumbnailer 2.2.2. The source video was a 10-second, 640×360, 30 fps MP4 with H.264 video and mono AAC audio, generated from FFmpeg's test pattern (testsrc2) and a 440 Hz sine wave. I did not test how it displays in Windows Explorer, macOS Finder, smartphones, or video streaming services.
- 1. What the command does, and the embedded result
- 2. If you forget attached_pic, you get an extra video track
- 3. Whether a thumbnail tool uses the embedded image
- 4. PNG works, but WebP does not work as-is
- 5. When re-encoding the video, keep only the image stream as copy
- 6. Using a frame from the video as the cover image
- 7. Replacing or removing the cover image
What the command does, and the embedded result
For the cover image, I used a 1280×720 JPEG (18,577 bytes) with "COVER" written in white on a light blue background. Each part of the command above does the following:
-i input.mp4 -i cover.jpg: reads the video as input 0 and the image as input 1-map 0 -map 1: includes all streams from input 0 and the image from input 1 in the output-c copy: copies the video, audio, and image without re-encoding-disposition:v:1 attached_pic: treats the second video stream in the output (v:1, the image in this case) as an "attached picture"
The FFmpeg official documentation for -disposition also shows a command of this form as an example of embedding a cover image. However, the official example adds -c:v:1 png, which converts the image to PNG before embedding. Running the official example as written also embedded the image successfully.
When I checked the embedded output.mp4 (with_cover.mp4 in my test) with ffprobe, a JPEG (mjpeg) appeared as the third stream, with attached_pic=1.
ffprobe -v error -show_entries stream=index,codec_name,codec_type,width,height:stream_disposition=default,attached_pic -of compact=p=0 with_cover.mp4
index=0|codec_name=h264|codec_type=video|width=640|height=360|disposition:default=1|disposition:attached_pic=0
index=1|codec_name=aac|codec_type=audio|disposition:default=1|disposition:attached_pic=0
index=2|codec_name=mjpeg|codec_type=video|width=1280|height=720|disposition:default=0|disposition:attached_pic=1
The file size grew from 1,163,821 bytes to 1,182,422 bytes, an increase of 18,601 bytes. That is only 24 bytes more than the image's 18,577 bytes.
ffprobe shows the image as a third stream, but inside the MP4 it is not a video track. When I walked the MP4 boxes with a Python script, there were only two tracks (trak), one video and one audio. The image was stored under covr in moov/udta/meta/ilst, where tag information is kept, with the JPEG type code (13).
/moov/trak/mdia/hdlr handler_type=vide
/moov/trak/mdia/hdlr handler_type=soun
/moov/udta/meta/ilst/covr/data type=13(JPEG) bytes=18577
Other tag-reading tools also showed the same image. AtomicParsley's -t printed Atom "covr" contains: 1 piece of artwork, and mutagen showed one 18,577-byte JPEG in covr.
You can extract the embedded image by selecting that stream with -map 0:v:1 and copying it:
ffmpeg -i with_cover.mp4 -map 0:v:1 -c copy -update 1 extracted.jpg
md5sum cover.jpg extracted.jpg
dac0eab968b8cd8f9e926e4c8ccb8920 cover.jpg
dac0eab968b8cd8f9e926e4c8ccb8920 extracted.jpg
The MD5 hashes match, so the JPEG was stored without re-encoding.
If you forget attached_pic, you get an extra video track
I ran the same command without -disposition:v:1 attached_pic. There was no error, and the exit code was 0. However, the image did not end up in covr.
ffmpeg -i input.mp4 -i cover.jpg -map 0 -map 1 -c copy no_disp.mp4
index=0|codec_name=h264|codec_type=video|duration=10.000000|nb_frames=300|disposition:default=1|disposition:attached_pic=0
index=1|codec_name=aac|codec_type=audio|duration=10.000000|nb_frames=470|disposition:default=1|disposition:attached_pic=0
index=2|codec_name=mjpeg|codec_type=video|duration=0.040000|nb_frames=1|disposition:default=0|disposition:attached_pic=0
The third stream is a video stream with a duration of 0.04 seconds and one frame. Inside the MP4, there are two video tracks (vide), and there is no covr. AtomicParsley also found no covr.
Whether a thumbnail tool uses the embedded image
I used ffmpegthumbnailer to generate a thumbnail from the embedded with_cover.mp4. According to the Ubuntu manual page, the -m option means "prefer the embedded image over the video content."
ffmpegthumbnailer -i with_cover.mp4 -o thumb.png -s 560
ffmpegthumbnailer -m -i with_cover.mp4 -o thumb_m.png -s 560

Without -m, the thumbnail was taken from a frame in the middle of the video, even though a cover image was embedded. The thumbnail made at the original size matched the video frame at 8.3333 seconds exactly. With -m, the embedded image became the thumbnail.
The no_disp.mp4 file, which was missing attached_pic, also produced the embedded image as the thumbnail when I used -m with ffmpegthumbnailer. Because the ffmpegthumbnailer output alone does not reveal the missing attached_pic, the reliable check is to confirm with ffprobe that attached_pic=1 is set after embedding.
PNG works, but WebP does not work as-is
I also embedded cover.png, a PNG version of cover.jpg (75,741 bytes), with the same command. It was stored in covr with the PNG type code (14).
/moov/udta/meta/ilst/covr/data type=14(PNG) bytes=75741
When I tried to embed a WebP image with -c copy, the command failed. (I omitted the numbers after @.) The exit code was 234, and the leftover file was 0 bytes.
[mp4 @ …] Could not find tag for codec webp in stream #2, codec not currently supported in container
[out#0/mp4 @ …] Could not write header (incorrect codec parameters ?): Invalid argument
In this case, converting only the image stream to JPEG with -c:v:1 mjpeg allowed the embedding to succeed:
ffmpeg -i input.mp4 -i cover.webp -map 0 -map 1 -c copy -c:v:1 mjpeg -disposition:v:1 attached_pic output.mp4
When re-encoding the video, keep only the image stream as copy
I removed -c copy to try to re-encode the video while embedding the image, and it failed.
ffmpeg -i input.mp4 -i cover.jpg -map 0 -map 1 -disposition:v:1 attached_pic no_copy.mp4
Stream #1:0 -> #0:2 (mjpeg (native) -> h264 (libx264))
(略)
[mp4 @ …] Could not find tag for codec h264 in stream #2, codec not currently supported in container
[out#0/mp4 @ …] Could not write header (incorrect codec parameters ?): Invalid argument
Error while filtering: Invalid argument
Conversion failed!
This happened because FFmpeg tried to convert the image stream to H.264 as well, and the MP4 container could not hold it. The exit code was 234. The leftover file was 0 bytes, and ffprobe could not open it.
By giving different options for the video and the image, I was able to re-encode the video and embed the image in one pass. -c:v:0 is for the first video, and -c:v:1 is for the image. The video was re-encoded, and the file size went from 1,163,821 bytes to 703,510 bytes.
ffmpeg -i input.mp4 -i cover.jpg -map 0 -map 1 -c:v:0 libx264 -crf 28 -c:a copy -c:v:1 copy -disposition:v:1 attached_pic output.mp4
index=0|codec_name=h264|codec_type=video|disposition:attached_pic=0
index=1|codec_name=aac|codec_type=audio|disposition:attached_pic=0
index=2|codec_name=mjpeg|codec_type=video|disposition:attached_pic=1
Using a frame from the video as the cover image
You can also pull a frame you like from the video and embed it directly, without preparing a separate image. Here is an example using the frame at 5 seconds:
ffmpeg -ss 5 -i input.mp4 -frames:v 1 -update 1 frame5.jpg
ffmpeg -i input.mp4 -i frame5.jpg -map 0 -map 1 -c copy -disposition:v:1 attached_pic output.mp4
The cover image was stored as a 640×360 JPEG, the same size as the video.
Replacing or removing the cover image
When I added a new image to an MP4 that already had a cover image, using the same -map 0 -map 1, the old image was kept too. This is because -map 0 also selects the stream of the old cover image.
ffmpeg -i with_cover.mp4 -i cover.png -map 0 -map 1 -c copy -disposition:v:2 attached_pic replaced_map0.mp4
index=2|codec_name=mjpeg|codec_type=video|disposition:attached_pic=1
index=3|codec_name=png|codec_type=video|disposition:attached_pic=1
AtomicParsley also showed Atom "covr" contains: 2 pieces of artwork.
To replace the image, use -map 0:V. According to the official documentation on stream specifiers, lowercase v selects all video streams, while uppercase V selects only the video streams that are not attached pictures or cover images.
ffmpeg -i with_cover.mp4 -i cover.png -map 0:V -map 0:a -map 1 -c copy -disposition:v:1 attached_pic replaced.mp4
index=0|codec_name=h264|codec_type=video|disposition:attached_pic=0
index=1|codec_name=aac|codec_type=audio|disposition:attached_pic=0
index=2|codec_name=png|codec_type=video|disposition:attached_pic=1
The old JPEG was removed, and only the new PNG remained. To remove the cover image, do not read the image (-i cover.png), and use only -map 0:V -map 0:a.
ffmpeg -i with_cover.mp4 -map 0:V -map 0:a -c copy removed.mp4
The file had only two streams, video and audio, and AtomicParsley found no covr.
The 1 in -disposition:v:1 is the order of the video streams in the output. If you read a video that already has a cover image with -map 0 -map 1, the new image becomes v:2. If you write -disposition:v:1 in this case, the command finishes without an error, but covr still holds the old JPEG, and the new PNG is stored as a one-frame video track. After embedding, use ffprobe to check which stream has attached_pic=1.





