24

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.

MultiplyByZer0
  • 6,302
  • 3
  • 32
  • 48
cooder_one
  • 301
  • 1
  • 2
  • 11

2 Answers2

36

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
Gyan
  • 85,394
  • 9
  • 169
  • 201
  • How do i know the version of the ffmpeg, i downloaded the latest static version from official site. – cooder_one Feb 16 '19 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 ;) – Tim Kuipers Apr 25 '19 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. – Tim Kuipers Apr 25 '19 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 02 '23 at 06: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.

Mark Slater
  • 141
  • 2
  • 9
  • 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 '21 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 '23 at 10:10
  • The higher ranked [answer](https://stackoverflow.com/a/54719926/199400) shows just that! No need to specify the cover image format in an argument, it's autodetected. – porg Apr 11 '23 at 10:15