How can I add thumbnails to multiple videos using bash and ffmpeg?

0
6
Asked By CuriousCat42 On

I'm working with a folder that contains several videos and images, and I want to use ffmpeg to add thumbnails to my videos. The command I know for adding a thumbnail to a single video is: `ffmpeg -i input.mkv -attach image.jpg -metadata:s:t:0 mimetype=image/jpeg -c copy output.mkv`. The videos are named with a numerical prefix, such as `00001 - vidname.mkv`, and the corresponding images follow a similar naming convention like `00001.jpg`. My goal is to attach the images to the videos based on these prefixes, for example attaching `00001.jpg` to `00001 - vidname.mkv`. Any advice on how to automate this process using bash?

1 Answer

Answered By CodeCrafter99 On

You can extract the prefix of each video and match it with the corresponding image like so:

```bash
for video in *.mkv; do
prefix="${video%%[^0-9]*}".jpg
output="${video%.mkv}.out.mkv"
echo ffmpeg -i "$video" -attach "$prefix" -metadata:s:t:0 mimetype=image/jpeg -c copy "$output"
done
```

This script iterates through your `.mkv` files, finds the matching `.jpg` based on the prefix, and prepares the command to run. Just remove the `echo` to execute the commands!

User123 -

Great tip! Just to clarify, this script assumes your image and video names have the same prefix, right?

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.