How to Batch Convert Files with FFmpeg on Windows

This guide provides a straightforward tutorial on how to use FFmpeg within a Windows batch script (.bat) to automate the conversion of multiple media files in a folder. You will learn the correct command-line syntax, how to structure a reusable script, and how to handle file names and formats efficiently without manually processing each file.

Prerequisites

Before running the script, ensure that FFmpeg is installed on your Windows system and added to your system’s PATH environment variable so it can be run from any directory.

The Basic Batch Conversion Command

If you want to run a quick loop directly in the Windows Command Prompt (CMD) without creating a script file, use the following syntax. This example converts all .wav files in the current folder to .mp3:

for %i in (*.wav) do ffmpeg -i "%i" "%~ni.mp3"

Writing the Windows Batch Script (.bat)

To save and reuse the command, you must create a batch script. In a batch script file, percent signs must be doubled (%%i instead of %i).

Step 1: Create the Batch File

  1. Open Notepad (or any text editor).
  2. Copy and paste the following code into the editor:
@echo off
:: Change the extensions below to match your source and target formats
set "source_ext=*.mkv"
set "dest_ext=mp4"

for %%i in (%source_ext%) do (
    ffmpeg -i "%%i" -codec copy "%%~ni.%dest_ext%"
)

echo Conversion complete!
pause

Step 2: Save the Script

  1. Go to File > Save As.
  2. Navigate to the folder containing the files you want to convert.
  3. Change the Save as type dropdown to All Files (.).
  4. Name the file convert.bat and click Save.

Step 3: Run the Script

Double-click the convert.bat file in your folder. A Command Prompt window will open, and FFmpeg will convert all target files in that folder sequentially.

Advanced Customization

Converting Files in Subfolders (Recursive)

To convert files in the current folder and all of its subfolders, add the /R flag to the loop:

@echo off
for /R %%i in (*.png) do (
    ffmpeg -i "%%i" "%%~ni.jpg"
)
pause

Customizing Video and Audio Codecs

You can add standard FFmpeg arguments inside the loop to control the quality and encoding settings. For example, to convert video files to H.264 video and AAC audio:

@echo off
for %%i in (*.avi) do (
    ffmpeg -i "%%i" -c:v libx264 -crf 23 -c:a aac -b:a 192k "%%~ni.mp4"
)
pause