I'm trying to embed a thumbnail image into MKV files using FFmpeg, and I'm looking for a way to automate the process for all the videos in a folder. Each video has a matching thumbnail with the same base name but different extensions (.mkv for the video and .jpg for the thumbnail). What's the best way to run a command that does this for each pair of files?
1 Answer
You can run a simple bash script to do this for all MKV files in your current directory. Here's a snippet you can use:
```bash
#!/usr/bin/env bash
for i in *.mkv; do
filename="${i::-4}"
ffmpeg -i "${filename}.mkv" -attach "${filename}.jpg" -metadata:s:t:0 mimetype=image/jpeg -c copy "${filename}_withthumbnail.mkv"
done
```
Just make sure your video and thumbnail filenames match! This way, each MKV will have the thumbnail embedded successfully.
That's exactly what I wanted. Thank you for your time!