Batch Convert WAV to AAC with PowerShell and FFmpeg

This article provides a step-by-step guide on how to write and run a PowerShell script to batch convert WAV audio files to the compressed AAC format on Windows using FFmpeg. You will learn how to set up the necessary tools, write a simple script to automate the process, and execute it efficiently to convert multiple files at once.

Prerequisites

Before running the script, ensure you have the following set up on your Windows system: 1. FFmpeg installed: Download FFmpeg and ensure it is added to your system’s PATH environment variable so PowerShell can recognize the ffmpeg command. 2. PowerShell: Windows PowerShell (built into Windows) or PowerShell Core.

The PowerShell Batch Conversion Script

To convert all .wav files in a folder to .aac, use the following PowerShell script. This script loops through every WAV file in the directory, applies the FFmpeg conversion, and outputs high-quality AAC files.

# Get all WAV files in the current directory
$wavFiles = Get-ChildItem -Filter *.wav

# Loop through each WAV file and convert it to AAC
foreach ($file in $wavFiles) {
    # Define the output file path with the .aac extension
    $outputFile = [System.IO.Path]::ChangeExtension($file.FullName, ".aac")
    
    # Run FFmpeg conversion with AAC audio codec at 192k bitrate
    ffmpeg -i "$($file.FullName)" -c:a aac -b:a 192k "$outputFile"
}

Write-Host "Batch conversion completed!" -ForegroundColor Green

How to Run the Script

  1. Open Notepad or your preferred text editor.

  2. Copy and paste the script code above into the editor.

  3. Save the file with the name convert.ps1 inside the folder where your .wav files are located. Make sure the file extension is .ps1 and not .ps1.txt.

  4. Open PowerShell and navigate to the folder containing your WAV files and the script using the cd command:

    cd "C:\path\to\your\audio\folder"
  5. Run the script by typing:

    .\convert.ps1
  6. If Windows blocks the execution due to script policies, bypass the restriction for this session by running:

    Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
    .\convert.ps1

Script Customization Options