mullnerz
4/21/2015 - 9:02 PM

mass converting video files using powershell and handbrake

mass converting video files using powershell and handbrake

# originated from:
# https://perfp.wordpress.com/2010/08/25/mass-converting-video-files-using-powershell-and-handbrake/

$outdir = "C:\Temp\convert-avi"

[Environment]::CurrentDirectory=(Get-Location -PSProvider FileSystem).ProviderPath
 $files = Get-Childitem -Recurse -Include "*.avi"
foreach ($file in $files) {
 $subpath = $file.DirectoryName.Replace((Get-Location -PSProvider FileSystem).ProviderPath , "")
 $destdir = $outdir + $subpath
 $destname = $destdir + "\" + $file.BaseName + ".mp4"
 if (!(Test-Path $destdir)) {
  New-Item $destdir -type directory
 }
 if (!(Test-Path $destname)) {
 & "C:\Program Files\Handbrake\HandBrakeCLI.exe" -i $file -t 1 -c 1 -o $destname --preset "Normal"
 }
}