With the help of Google, I put together a Powershell script for Handbrake automation.
What it does:
- Some files are downloaded automatically via RSS. They are placed in the source folder.
- The Powershell script executes Handbrake, encoding starts and successfully gets over.
- If no new files arrive in the source folder, the script exits.
The issue is with the last item. When the source folder is empty the Powershell script exits, but I want it to continue running and process more files when they arrive, until I kill it. When a new file is added, it should automatically start encoding.
Code is in PasteBin which has more comments but should be easy to infer what the script does:
$inputpath = "I:\S"
$outputpath = "I:\E"
$movies = ls $inputpath
foreach($movie in $movies){
$name = $movie.basename
if(!(test-path -path "$outputpath\$name.mkv")){
C:\"Program Files"\handbrake\HandBrakeCLI.exe -i "$inputpath\$movie" -o "$outputpath\$name.mkv" `
-e x264 -b 1000 -2 -T -a 1,1 -E mp3 -B 112 --mixdown stereo -f mkv --detelecine --decomb `
--loose-anamorphic -m -x rc-lookahead=30:ref=4:bframes=3:me=umh:subme=9:analyse=none:deblock=1:0:0:8x8dct=1
}
}