-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandbrake_batch.sh
executable file
·94 lines (77 loc) · 2.51 KB
/
handbrake_batch.sh
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
rand=$RANDOM$RANDOM
progress_fname="progress_$rand.txt"
log_fname="log_$rand.txt"
HB_PID=0
TAIL_PID=0
confirm () {
read -r -p "${1:-Would you like to continue? [y/N]} " response
case $response in
[yY][eE][sS]|[yY])
true
;;
*)
false
;;
esac
}
function cleanup {
kill -15 $HB_PID 2>&1 >/dev/null
kill -15 $TAIL_PID 2>&1 >/dev/null
rm -f "$progress_fname" "$log_fname" > /dev/null;
exit
}
trap cleanup SIGHUP SIGINT SIGKILL SIGTERM SIGSTOP
args=("$@")
if [ $# -eq 0 ] || [ $# -eq 1 ]; then
echo "Correct usage:"
echo " scriptname [output directory] [file list]"
else
numOfElems=${#args[@]}
outputDir=${args[0]}
currentDirectory=`pwd`
echo "* * * * * * * * * * * * * * * * * * * * * * * * * * * *"
echo "*"
echo "* Input filetype: $filetype"
# get and print full output directory
cd "$outputDir"; echo "* Output Directory: $(pwd)"; cd "$currentDirectory"
echo "* Number of files: $(($numOfElems-1))"
echo "* Files:"
for (( i=1;i<$numOfElems;i++)); do
echo "* ${args[${i}]}"
done
echo "*"
echo "* * * * * * * * * * * * * * * * * * * * * * * * * * * *"
confirm &&
for (( i=1;i<$numOfElems;i++)); do
# echo "" > "$fname"
echo "* * * * * * * * * * * * * * * * * * * * * * * * * * * *"
echo "*"
echo "* Processing:"
echo "* `sed 's/\....//'<<<${args[$i]}`"
echo "*"
echo "* * * * * * * * * * * * * * * * * * * * * * * * * * * *"
# handbrakecli -e x264 -q 20.0 -r 30 --pfr -a 1,1 -E ffaac,copy:ac3 -B 160,160 -6 dpl2,none -R Auto,Auto -D 0.0,0.0 --audio-copy-mask aac,ac3,dtshd,dts,mp3 --audio-fallback ffac3 -f mp4 -X 1920 -Y 1080 --decomb=fast --loose-anamorphic --modulus 2 -m --x264-preset medium --h264-profile high --h264-level 4.0 -i "${args[$i]}" -o $outputDir/"${args[$i]%.$filetype}.mp4" 1> "$progress_fname" 2> "$log_fname" &
handbrakecli -Z "AppleTV 2" -i "${args[$i]}" -o $outputDir/"`sed 's/\....//'<<<${args[$i]}`.mp4" 1> "$progress_fname" 2> "$log_fname" &
toggle=true
sleep 1;
HB_PID=$!
while pgrep handbrakecli > /dev/null;
do
# check if tail has been started, start if not
if $toggle; then
tail -f -n 1 "$progress_fname" &
toggle=false
TAIL_PID=$!
fi
sleep 10;
# if handbrake has finished running, stop tail
if ! pgrep handbrakecli > /dev/null; then
kill -15 $TAIL_PID 2>/dev/null
wait $TAIL_PID 2>/dev/null
fi
done;
rm -f "$progress_fname" "$log_fname" > /dev/null;
echo "Finished converting ${args[$i]%.$filetype}";
done;
fi