-
Notifications
You must be signed in to change notification settings - Fork 0
/
encode_script.sh
129 lines (86 loc) · 2.07 KB
/
encode_script.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
#Handbrake batch script to recursively encode every file in a certain directory
function check
{
oldsize=`wc -c <"$f"`
sleep 1
newsize=`wc -c <"$f"`
while [ "$oldsize" -lt "$newsize" ]
do
echo "Not yet..."
oldsize=`wc -c <"$f"`
sleep 1
newsize=`wc -c <"$f"`
done
if [ "$oldsize" -eq "$newsize" ]
then
echo "The file has been copied completely."
fi
}
FILES="/home/usr/Documents/Watch/*"
PRESET="-e x264 -q 20 --x264-preset veryfast"
#//////////////////////////////////////////
#exec 3>&1 4>&2
#trap 'exec 2>&4 1>&3' 0 1 2 3
#exec 1>LOGFILE 2>&1
#//////////////////////////////////////////
function main
{
for f in $FILES
do
##################################################
#printf "Current date and time %s\n" "$now"
##################################################
if [[ $f =~ \.mp4$ ]];
then
#/////////////////////////////////////////////////////////////////////
g="${f/mp4/mkv}"
g=${g/"Watch"/"Output"}
LOG_FILE="${g/mkv/log}"
exec > >(tee -a "${LOG_FILE}" )
exec 2> >(tee -a "${LOG_FILE}" >&2)
now="$(date)"
printf "Current date and time %s\n" "$now"
check
echo "Processing ${f} file..."
HandBrakeCLI -i "${f}" -o "${g}" "$PRESET"
rm "$f"
fi
#/////////////////////////////////////////////////////////////////////
if [[ $f =~ \.avi$ ]];
then
g="${f/avi/mkv}"
g=${g/"Watch"/"Output"}
LOG_FILE="${g/mkv/log}"
exec > >(tee -a "${LOG_FILE}" )
exec 2> >(tee -a "${LOG_FILE}" >&2)
now="$(date)"
printf "Current date and time %s\n" "$now"
check
echo "Processing ${f} file..."
HandBrakeCLI -i "${f}" -o "${g}" "$PRESET"
rm "$f"
fi
if [[ $f =~ \.mov$ ]];
then
g="${f/mov/mkv}"
g=${g/"Watch"/"Output"}
LOG_FILE="${g/mkv/log}"
exec > >(tee -a "${LOG_FILE}" )
exec 2> >(tee -a "${LOG_FILE}" >&2)
now="$(date)"
printf "Current date and time %s\n" "$now"
check
echo "Processing ${f} file..."
HandBrakeCLI -i "${f}" -o "${g}" "$PRESET"
rm "$f"
fi
done
#if [ "$(ls -A /home/usr/Documents/Watch/)" ]; then
#main
#fi
}
if [ "$(ls -A /home/usr/Documents/Watch/)" ]; then
main
fi
exit