25

I am trying to find the proper ffmpeg command to add a .png or .jpg image to a .mp4 video as a thumbnail. The command will eventually automatically be executed by a C# program.

This is what I have so far:

# This does not work. It only removes the default thumbnail.
ffmpeg -i video.mp4 -i image.png -acodec copy -vcodec copy -map 0 -map 1:0 OUTPUT.mp4

Is what I want possible with ffmpeg? If so, please guide me in the right direction.

2 Answers 2

37

Using ffmpeg 4.0, released Apr 20 2018 or newer,

ffmpeg -i video.mp4 -i image.png -map 1 -map 0 -c copy -disposition:0 attached_pic out.mp4
4
  • How do i know the version of the ffmpeg, i downloaded the latest static version from official site.
    – cooder_one
    Feb 16, 2019 at 14:49
  • 3
    @cooder_one Run ffmpeg -version in a terminal. Mine is 3.4.4-0ubuntu0.18.04.1 while we need version 4.0 or higher. My package manager is running at least 5 days behind ;) Apr 25, 2019 at 11:31
  • 2
    This changes the thumbnail my Ubuntu OS is showing when viewing files in Nemo; it doesn't work for getting Youtube to automatically propose the custom image as a thumbnail for my video. Apr 25, 2019 at 11:56
  • @Gyan Could you explain what each part means? I'm scrolling trough the man page trying to understand what you did there, but it would be much easier for you to write 3 lines. I would be very grateful :)
    – Thunermay
    Jun 2 at 6:10
9

As in version 4.2.2...See Section 5.4 in FFmpeg documentation

To add an embedded cover/thumbnail:

ffmpeg -i in.mp4 -i IMAGE -map 0 -map 1 -c copy -c:v:1 png -disposition:v:1 attached_pic out.mp4

Not all muxers support embedded thumbnails, and those who do, only support a few formats, like JPEG or PNG.

3
  • 12
    It's not necessary obvious without knowing the doc conventions, but IMAGE is an image filename, and attached_pic is a keyword (it's a parameter for the -disposition option)
    – mwfearnley
    Feb 16, 2021 at 13:57
  • 1
    What's also not obvious for the occassional ffmpeg user is: How do I embed a cover image of the different filetypes (png, jpg, webp)? Ideally auto-detected from the supplied image (the second -i argument). If that's not possible and you have to set it manually, how? Simply replacing the png in -c copy -c:v:1 png with jpg or jpeg or webp all failed with Unknown encoder.
    – porg
    Apr 11 at 10:10
  • The higher ranked answer shows just that! No need to specify the cover image format in an argument, it's autodetected.
    – porg
    Apr 11 at 10:15

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.