Batch Convert WAV to AAC with PowerShell and FFmpeg
Converting multiple uncompressed WAV audio files into high-efficiency AAC files on Windows can save significant disk space while maintaining high audio quality. This guide provides a ready-to-run PowerShell script that utilizes FFmpeg to automatically scan a directory, convert every WAV file to an AAC format, and output the encoded files cleanly to a specified folder.
Prerequisites
Before running the script, ensure you have FFmpeg installed on your system. You can verify this by opening a PowerShell prompt and running:
ffmpeg -versionIf the command is not recognized, download FFmpeg, extract it, and
add its bin folder to your Windows system's Environment
Variables (PATH).
The Batch Conversion Script
Open a text editor (such as Notepad or VS Code), paste the following
script, and modify the $sourceDir and
$targetDir paths to match your folder locations:
# Define source and destination directories
$sourceDir = "C:\Audio\WAV_Files"
$targetDir = "C:\Audio\AAC_Files"
$bitrate = "192k"
# Create target directory if it does not exist
if (-not (Test-Path -Path $targetDir)) {
New-Item -ItemType Directory -Path $targetDir -Force | Out-Null
}
# Fetch all WAV files in the source directory
$wavFiles = Get-ChildItem -Path $sourceDir -Filter *.wav -File
if ($wavFiles.Count -eq 0) {
Write-Host "No WAV files found in $sourceDir" -ForegroundColor Yellow
exit
}
# Loop through each WAV file and convert to AAC
foreach ($file in $wavFiles) {
$outputPath = Join-Path -Path $targetDir -ChildPath "$($file.BaseName).m4a"
Write-Host "Converting: $($file.Name) -> $($file.BaseName).m4a" -ForegroundColor Cyan
# Run FFmpeg conversion
& ffmpeg -hide_banner -loglevel error -stats -i $file.FullName -c:a aac -b:a $bitrate -y $outputPath
}
Write-Host "Batch conversion completed successfully." -ForegroundColor GreenScript Breakdown
Get-ChildItem -Filter *.wav -File: Scans the source folder specifically for files ending with.wav. To include subdirectories recursively, add the-Recurseflag.$file.BaseName: Extracts the file name without the.wavextension, allowing the script to append the appropriate container extension..m4aExtension: AAC streams are typically wrapped in an MP4/M4A container for maximum player compatibility on Windows and macOS. If you require raw ADTS AAC streams, change the extension to.aac.-c:a aac: Specifies the native FFmpeg AAC audio encoder.-b:a 192k: Sets the target audio bitrate to 192 kbps. You can adjust this value (e.g.,128k,256k, or320k) based on your quality requirements.-hide_banner -loglevel error -stats: Suppresses unnecessary FFmpeg licensing information and limits the output to errors and progress updates.-y: Overwrites output files automatically if they already exist.
How to Run the Script
Save the file with a
.ps1extension, such asconvert-wav-to-aac.ps1.Open PowerShell and navigate to the directory where the script is saved.
If running scripts is restricted on your system, allow execution for the current session by running:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy BypassExecute the script:
.\convert-wav-to-aac.ps1