Is it possible to add a custom thumbnail using ffmpeg to a .webm file?

Is there any way to add a custom thumbnail to a .webm file using FFmpeg?
I tried the following commands using FFmpeg version: 4.2.7-0ubuntu0.1, but not working for me :frowning:

ffmpeg -i ‘input.webm’ -i ‘thumbnail.jpg’ -map 1 -map 0 -c copy -disposition:0 attached_pic ‘output.webm’

Yes, it is possible to add a custom thumbnail to a .webm file using FFmpeg.

You can use the “thumbnail” filter in FFmpeg.
Here is an example command that will extract a thumbnail from the video at the 5-second mark and save it to a file named “thumbnail.jpg”:

ffmpeg -i input.webm -vf "thumbnail,scale=640:360" -frames:v 1 thumbnail.jpg

To add the thumbnail to the .webm file as a poster image, you can use the “metadata” option in FFmpeg. Here is an example command that will add the thumbnail to the .webm file as a poster image:

ffmpeg -i input.webm -i thumbnail.jpg -map 0 -map 1 -c copy -c:v:1 image2 -metadata:s:v:1 title="Album cover" -metadata:s:v:1 comment="Cover (front)" output.webm

The above command will take the input video “input.webm” and the thumbnail image “thumbnail.jpg” and create a new .webm file “output.webm” with the thumbnail added as a poster image.

Let me try this and then will get back to you if need more help. Thanks

Can you specify the position and duration of the thumbnail in the .webm file?

1 Like

Sadly, unlike some other formats, the WebM format itself does not inherently allow the idea of thumbnails with precise placements or durations. Typically, the FFmpeg-attached thumbnail will be a static image linked to the full video.

It could be worthwhile to think about other options if you require advanced thumbnail functionality, like making a brief video clip that functions as a thumbnail and then adding it to the WebM file.

1 Like

Got it, can the process of adding a custom thumbnail be automated for batch processing with FFmpeg?

1 Like

Yes, you can use a script or a loop to automate the bulk processing process. This is very useful if you have several .webm files with associated thumbnail photos. Using FFmpeg, a straightforward script may loop through the files and attach the matching thumbnails, expediting the process for numerous videos.

#!/bin/bash
for file in *.webm; do
  thumbnail="thumbnail_${file%.webm}.jpg"
  ffmpeg -i "$file" -i "$thumbnail" -c copy -map 0 -map 1 -metadata:s:v title="Thumbnail" -metadata:s:v comment="Thumbnail" "output_${file}"
done

Every .webm file in the current directory is processed by this script, which also adds the relevant thumbnail and saves the result with a new filename. Adapt the script to your directory layout and file naming conventions.

1 Like

Thank you for your quick response.