Convert all files in a folder with ffmpeg (script)
ffmpeg processes one file at a time, but a short loop in the terminal can convert an entire folder. Choose your system, the type of files to process and the operation: the script is generated for you. The results are written to a subfolder, and your originals are not modified.
Updated on
Without the dot. One file type at a time.
How to use it
- Install ffmpeg if you haven't already.
- Open a terminal in the folder that contains the files to convert.
- Copy the script, paste it into the terminal and press Enter: each file is processed one after the other.
- Find the results in the output subfolder, created next to your files.
What the script does
It creates a subfolder, then goes through all the files in the current folder that have the specified extension. Each one is converted with the chosen options and saved under the same name, with the new extension. The -n option prevents overwriting a file that has already been converted: if you rerun the script after an interruption, ffmpeg displays an "already exists" message for each existing file, skips it and moves on to the next one.
Before running it on a whole folder
Test it first on a copy of two or three files: a wrong option applied to hundreds of videos wastes a lot of time. The script does not process subfolders, and on Linux and macOS the extension is case-sensitive (mkv and MKV are two different extensions). For several extensions, run the script again for each one.
Frequently asked questions
Are my original files modified?
No. The results are written to the output subfolder, and the originals stay intact.
Why does ffmpeg sometimes ask for confirmation?
Without the -n option, ffmpeg asks whether it should overwrite an existing file, which blocks the loop. The script includes it to avoid this.
How do I process subfolders too?
This script does not go through them. You need a recursive command (find on Linux and macOS, Get-ChildItem with -Recurse in PowerShell), which is longer and should be used with caution.
The terminal says "ffmpeg is not recognized". What should I do?
Either ffmpeg is not installed or the terminal needs to be reopened. Follow the installation guide, then check with ffmpeg -version.