Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Batch-encode all .MKV containers in a directory to AppleTV-compatible .MP4
$scandir = "d:\video"
$outputdir = "d:\encoded"
$filelist = Get-ChildItem $scandir -filter *.mkv -recurse
$num = $filelist | measure
$filecount = $num.count
$i = 0;
ForEach ($file in $filelist)
{
$i++;
$oldfile = $file.DirectoryName + "\" + $file.BaseName + $file.Extension;
$newfile = $outputdir + "\" + $file.Directory.Name + ".m4v";
$progress = ($i / $filecount) * 100
$progress = [Math]::Round($progress,2)
Clear-Host
Write-Host -------------------------------------------------------------------------------
Write-Host Handbrake Batch Encoding
Write-Host "Processing - $oldfile -> $newfile"
Write-Host "File $i of $filecount - $progress%"
Write-Host -------------------------------------------------------------------------------
Start-Process "d:\Program Files\HandBrake\HandBrakeCLI.exe" -ArgumentList "-i `"$oldfile`" -t 1 --angle 1 -o `"$newfile`" -f mp4 -w 720 --crop 56:64:10:4 --loose-anamorphic --modulus 2 -e x264 -q 20 -r 30 --pfr -a 1,1 -E av_aac,copy:ac3 -6 dpl2,none -R Auto,Auto -B 160,0 -D 0,0 --gain 0,0 --audio-fallback ac3 --native-language eng --subtitle scan --subtitle-forced --encoder-preset=fast --encoder-level=`"3.0`" --encoder-profile=baseline --verbose=0" -Wait -NoNewWindow
}
Owner

rpunt commented May 20, 2015

This assumes that all .mkv files are contained beneath d:\video\MOVIE TITLE*.mkv. Output placed in d:\encoded\MOVIE TITLE.m4v

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment