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 GreenHow to Run the Script
Open Notepad or your preferred text editor.
Copy and paste the script code above into the editor.
Save the file with the name
convert.ps1inside the folder where your.wavfiles are located. Make sure the file extension is.ps1and not.ps1.txt.Open PowerShell and navigate to the folder containing your WAV files and the script using the
cdcommand:cd "C:\path\to\your\audio\folder"Run the script by typing:
.\convert.ps1If 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
Adjusting Quality (Bitrate): The script uses
-b:a 192kto set the audio bitrate to 192 kbps. You can change this to128kfor smaller files, or256k/320kfor higher quality.Including Subfolders (Recursive): If your WAV files are organized inside multiple subfolders, you can scan and convert all of them recursively by adding the
-Recurseparameter to the first line:$wavFiles = Get-ChildItem -Filter *.wav -Recurse