Batch process files in a directory with FFMPEG and bash scripts

Copy the script below and save it using your preferred text editor. I would use nano since we are already working in a terminal window. Save it without a file extension or as a .sh if you must specify a file type.

The script uses the find command to search a directory, passes its results to ffmpeg for processing, and finally moves the files to your desired directory.

REPLACE THE FOLLOWING AS NEEDED:

searchDir = directory searched (this includes sub-directories)
*.MXF = search criteria (in this case I’m using the asterisk wildcard to find all files using the .MXF extension)
.mp4 = output files’ file extension
destDir = path where files are placed when finished processing

In order to run the script you will need to give it execute permissions

chmod +x script_name

Run the script in a terminal window by invoking it with ./script_name

#!/bin/bash

find searchDir -type f -iname "*.MXF" | while read src; do
dest=${src%.*}.mp4
echo "Converting $src -> $dest ..."
ffmpeg -i "$src" -options “$dest”
mv "$dest" destDir
done

Previous
Previous

Save YouTube video as MP# file with youtube-dl

Next
Next

Create proxy files with matching audio channels