fredag, mars 02, 2012

Handbrake and PowerShell

If you, like myself, has got a digital camera with HD capabilities but very limited encoding options then the following script might interest you. It traverses a folder structure scouting for movies to re-encode and then sets the new files creation time to the same as the old one. Then removes the old movie file. For encoding it uses Handbrake, a sweet little tool that is easy to use and produces good results.

set-alias hb "C:\Program Files\Handbrake\HandBrakeCLI.exe"
$files = get-childitem "F:\Movies" -recurse -filter *.mov
$log = "C:\log.txt"

foreach ($file in $files) {
    $old = $file.FullName
    $new = $file.FullName.Replace('.MOV','.mp4').Replace('.mov','.mpg4')

    hb -t 1 -c 1 -i "$old" -o "$new" -f mp4 --strict-anamorphic  -e x264 -q 20 --vfr  -a 1 -E faac -B 160 -6 dpl2 -R Auto -D 0 --gain=0 --audio-copy-mask none --audio-fallback ffac3 -x ref=1:weightp=1:subq=2:rc-lookahead=10:trellis=0:8x8dct=0 --verbose=1 2>&1 |
        out-file $log
        
    get-item $new | foreach { $_.CreationTime = $file.CreationTime }
    remove-item $old
}

Inga kommentarer: