-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathre-encode.ps1
36 lines (28 loc) · 1.49 KB
/
re-encode.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#get all raw mpeg2 recordings recursively
$shows = get-childitem "d:\plexdata\tvdvr", "d:\plexdata\moviedvr" -rec -include *.ts
foreach ($show in $shows) {
#ignore files actively being recorded in grab directory
if ($show.fullname -like "*.grab*") {continue}
#set variables of sourcefile and outfile of particular recording
#escape \ character required as period is interpreted as regex otherwise
$sourcefile = $show.fullname
$outfile = $sourcefile -replace "\.ts",".mp4"
#dont create outfile if it was already created
#if you ctrl-c a previous run leaving partial files, delete them yourself first
if (test-path $outfile) {continue}
#put together handbrakecli command for this particular recording
$cmd = '"c:\program files\handbrake\handbrakecli.exe" -i "' + $sourcefile + '" -o "' + $outfile + '" --preset "Very Fast 720p30" -s "1,2,3,4,5,6" --all-audio'
#run handbrake to make outfile
$cmd | cmd
#cleanup once done
#check if the outfile was created and if so if its at least 6.5% original size, delete sourcefile
#unsure if handbrake can have problems this is safety mechanism rather than just assume it will always work perfectly.
#If the outfile is at least 6.5% of original size its probably a good output file
if (test-path $outfile) {
$sourcefilesize = (get-item $sourcefile).length
$outfilesize = (get-item $outfile).length
if (($outfilesize / $sourcefilesize) -gt .065) {
remove-item $sourcefile
}
}
}