Batch Transcode Videos with Find, Xargs, and FFmpeg

Efficiently processing large numbers of video files is a common task for developers and multimedia administrators. This guide demonstrates how to combine the Unix find command, xargs, and ffmpeg to automate and parallelize the batch transcoding of video files. By chaining these commands, you can scan directories recursively, handle filenames with spaces safely, and utilize multiple CPU cores to speed up your rendering pipeline.

The Standard Batch Transcoding Command

To recursively find all .mkv files in a directory and transcode them to .mp4 using the H.264 video codec and AAC audio codec, run the following command in your terminal:

find . -type f -name "*.mkv" -print0 | xargs -0 -I {} -P 2 sh -c 'ffmpeg -y -nostdin -i "$0" -c:v libx264 -crf 23 -c:a aac "${0%.*}.mp4"' {}

Command Breakdown

To customize this pipeline for your specific workflow, it is important to understand how each component operates:

1. The find Command

2. The xargs Command

3. The ffmpeg Command