Last active
February 8, 2017 00:55
-
-
Save sterling/9dacbac2f99a030f232a41a884cdc5de to your computer and use it in GitHub Desktop.
Encode video files recursively while maintaining directory structure and file names on output. Uses Windows PowerShell and HandBrakeCLI.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gci . *.mp4 -R | | |
foreach-object { | |
$saveBase = "D:\handbrake" | |
$curDir = (Get-Item -Path ".\" -Verbose).FullName | |
$inName = $_.BaseName + $_.Extension | |
$inFile = $_.DirectoryName + "\" + $inName | |
$outFile = $saveBase + $inFile.replace($curDir, "") | |
$outDir = $outFile.replace($inName, "") | |
New-Item -path "$outDir" -type directory -force | |
if (Test-Path -LiteralPath $outFile) { | |
echo "Skipping $inFile" | |
} else { | |
echo "Working on $inFile" | |
echo "Saving to $outFile" | |
$exe = "C:\Program Files\HandBrake\HandBrakeCLI.exe" | |
$exeArgs = "-i `"$inFile`" -o `"$outFile`" --preset `"Very Fast 1080p30`"" | |
$proc = Start-Process $exe $exeArgs -NoNewWindow -PassThru | |
if (!$proc.WaitForExit(600000)) { #10 min | |
echo "Timed out $inFile" | |
$proc.kill() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment