I want to convert all videos in a directory from WebM format to MKV using FFmpeg. I know the basic command for converting a single file is `ffmpeg -i input.webm -c:v copy -c:a copy -c:s srt output.mkv`, but I need help figuring out how to apply that command to every WebM file in a folder. Also, I want the output files to retain their original names, only changing the file extension from .webm to .mkv.
2 Answers
To batch convert your videos, just write a bash script to iterate through the files. You’ll use the original file name to create the MKV output. You might ask ChatGPT for help with that by prompting:
"Please write a bash script that uses FFmpeg to convert all WebM videos in a folder to MKV without re-encoding, just copying data."
You can create a simple bash script to do this! Here’s how it works:
```bash
for wfile in *.webm; do
ffmpeg -i "$wfile" -c:v copy -c:a copy -c:s srt "${wfile/.webm/.mkv}"
done
```
This script loops through all the WebM files in your directory and uses FFmpeg to convert each one, changing the extension in the output file name accordingly.
Having an example command is super helpful! It cuts down on errors, especially when you're dealing with specific arguments.