Convert MKV to MP4 in Bulk with Find and FFmpeg

This guide provides a straightforward solution for batch converting multiple MKV video files into the MP4 format on Linux using a combination of the find command and ffmpeg. By leveraging these powerful command-line tools, you can automate the conversion process across an entire directory tree while preserving original video quality.

To convert your files efficiently, you will combine find to locate the files and ffmpeg to handle the transcoding. Because MKV and MP4 are both container formats that often hold the same underlying video and audio codecs (like H.264 and AAC), you can usually copy the streams without re-encoding them. This process is incredibly fast and preserves the exact quality of the original file.

The Batch Conversion Command

Run the following command in the terminal from the root directory containing your MKV files:

find . -type f -name "*.mkv" -exec sh -c 'for f; do ffmpeg -i "$f" -c copy "${f%.mkv}.mp4"; done' _ {} +

How the Command Works

Re-encoding the Video (When Stream Copying Fails)

If your MKV files contain older or unsupported codecs that do not play well inside an MP4 container, you will need to re-encode the video. Use the modified command below to compress the video using the widely compatible H.264 codec:

find . -type f -name "*.mkv" -exec sh -c 'for f; do ffmpeg -i "$f" -c:v libx264 -crf 23 -c:a aac "${f%.mkv}.mp4"; done' _ {} +

In this variation, -c:v libx264 encodes the video to H.264, -crf 23 manages the visual quality balance, and -c:a aac converts the audio to standard AAC format. This method takes longer than stream copying but ensures maximum compatibility across all media players and devices.