How do I add a custom thumbnail to a .mp4 file using ffmpeg?
Asked Answered
A

2

28

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.

Athanor answered 15/2, 2019 at 21:17 Comment(0)
A
44

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
Alcoholize answered 16/2, 2019 at 4:36 Comment(7)
How do i know the version of the ffmpeg, i downloaded the latest static version from official site.Athanor
@Athanor 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 ;)Waken
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.Waken
@Alcoholize 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 :)Unsteady
@Tim Kuipers After you upload the video to youtube they convert it to webm so that problay removes the changes you did on your local file.Davin
How to undo this and let the OS choose the thumbnail again?Davin
Remux the new file but don't map the thumbnail stream.Alcoholize
T
11

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.

Tsingyuan answered 8/4, 2020 at 14:33 Comment(3)
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)Avenge
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.Colleague
The higher ranked answer shows just that! No need to specify the cover image format in an argument, it's autodetected.Colleague

© 2022 - 2024 — McMap. All rights reserved.