FFmpeg Batch Conversion with Powershell

How to encodes multiple videos into different codec using ffmpeg and powershell

Recently I need to backup all of my videos from iPhone into my hard drive. The iOS by default record the videos in QuickTime .MOV format. Since it’s for archival purpose, I need to convert it into more portable format .mp4. My plan is to encode the video into H.264 and the audio into AAC format. The .mp4 file size is also relatively smaller than .MOV, so this is perfect for achival.

Since I’ll use ffmpeg on Windows, I need to write a powershell script for video conversion.

The script to convert one video is like following snippet.

ffmpeg.exe -i input.MOV -c:v libx264 -crf 18 -c:a aac -map_metadata 0 output.mp4

That’s easy if you only have a few videos. But it’s different story if you have a dozen or hundreds of files. To make thing easy, you need to write a powershell script that can batch convert your videos.

You can use following powershell script to batch convert the video files. Change it to whatever you need before using it. This’ll work if you need to convert all .MOV files inside a directory into .mp4 files.


$originalVids = Get-ChildItem *.MOV -Recurse

foreach ($inputVid in $originalVids) {
    $outputVid = [io.path]::ChangeExtension($inputVid.FullName, '.mp4')
    ffmpeg.exe -i $inputVid.FullName -c:v libx264 -crf 18 -c:a aac -map_metadata 0 $outputVid
}

Thank you for reading. Hope this simple script can help you.

References