Batch Convert Files with FFmpeg and Zsh on macOS

This article provides a quick, step-by-step guide on how to batch convert audio and video files on macOS using FFmpeg and a Zsh loop. You will learn the exact command structure to run directly in your Terminal, how to handle file extensions properly, and how to customize the loop for different formats.

The Basic Zsh Loop Structure

To batch convert files in macOS (which uses Zsh as the default shell), you can run a simple for loop directly in the Terminal.

Navigate to the folder containing your files using the cd command, and then run the following loop:

for f in *.wav; do ffmpeg -i "$f" "${f%.wav}.mp3"; done

How the Command Works

Batch Converting Video Files

The same logic applies to video files. If you want to convert a folder of .mkv files to .mp4 while copying the video stream and re-encoding the audio to AAC for compatibility, use this command:

for f in *.mkv; do ffmpeg -i "$f" -c:v copy -c:a aac "${f%.mkv}.mp4"; done

Running the Loop as a One-Liner or Multi-Line

You can paste the entire loop as a single line into your Terminal and press Enter. If you prefer readability, you can also type it out line-by-line:

for f in *.mkv
do
  ffmpeg -i "$f" -c:v copy -c:a aac "${f%.mkv}.mp4"
done

Both methods achieve the exact same result, allowing you to convert dozens of files in seconds without needing third-party GUI software.