Batch Convert Files with FFmpeg and PowerShell

This guide provides a straightforward walkthrough on how to write and execute an FFmpeg command to batch convert media files on Windows using PowerShell. You will learn the exact script syntax required to loop through a directory of files and convert them to your desired format efficiently.

To batch convert files in Windows PowerShell, you combine the Get-ChildItem cmdlet (which locates your files) with the ForEach-Object loop (which runs the FFmpeg command on each file).

Open PowerShell, navigate to the folder containing your media files using the cd command, and run the following command:

Get-ChildItem -Filter *.mkv | ForEach-Object { ffmpeg -i $_.FullName -codec copy ($_.BaseName + ".mp4") }

How the Command Works

Batch Converting Files in Subfolders (Recursive)

If your files are organized in subfolders and you want to convert all of them at once, add the -Recurse parameter to the search cmdlet:

Get-ChildItem -Filter *.wav -Recurse | ForEach-Object { ffmpeg -i $_.FullName ($_.DirectoryName + "\" + $_.BaseName + ".mp3") }

Using $_.DirectoryName + "\" ensures that the newly converted .mp3 files are saved in the exact same subfolder as their original .wav counterparts.