2
I am trying to batch encode a bunch of files. Looking over the internet I have found just a couple scripts and none of them worked for me. I started to piece together something and it is close to working minus one problem
The PRESET variable isn't working. I even tried removing the variable and put the code in and still didn't work. I am not sure I am allowed to use this type of command in find. I am sure there is a simpler more elegant way to do this.
#!/bin/bash
SRC="/home/usr/temp/encode"
PRESET="-e x264 -q 20.0 -E faac -B 128 -6 dpl2 -w 1280 --loose-crop --loose-anamorphic --x264-preset veryfast --h264-profile high --h264-level 4.1"
find $SRC -type f -name '*.mp4' -exec bash -c 'name="{}"; HandBrakeCLI -i "$name" -o "${name}.tmp" $PRESET && rm "$name" && mv "${name}.tmp" "$name"' \;
find $SRC -type f -name '*.wmv' -exec bash -c 'name="{}"; HandBrakeCLI -i "$name" -o "${name%.wmv}.mp4" $PRESET && rm "$name"' \;
find $SRC -type f -name '*.mov' -exec bash -c 'name="{}"; HandBrakeCLI -i "$name" -o "${name%.mov}.mp4" $PRESET && rm "$name"' \;
exit
If I was to do this file by file from the command line it would look like this
HandBrakeCLI -i "filename.mov" -o "filename.mp4" -e x264 -q 20.0 -E faac -B 128 -6 dpl2 -w 1280 --loose-crop --loose-anamorphic --x264-preset veryfast --h264-profile high --h264-level 4.1
If I was to resize an mp4 file I would do this so I wouldn't overwrite the file as it is encoding. That is why I have the extra stuff on the first find.
HandBrakeCLI -i "filename.mp4" -o "filename.NEW.mp4" -e x264 -q 20.0 -E faac -B 128 -6 dpl2 -w 1280 --loose-crop --loose-anamorphic --x264-preset veryfast --h264-profile high --h264-level 4.1
One issue:
PRESET
appears in single quotes. That means that it won't be evaluated until thebash -c
command is executed. You need to makePRESET
to that subshell. Therefore:PRESET=...
==>export PRESET=...
– John1024 – 2014-05-05T04:38:27.137@John1024 That is beyond my scope. I am very new to bash scripting. – J4204144 – 2014-05-05T05:47:23.200