-
Notifications
You must be signed in to change notification settings - Fork 1
/
hmdb_extract_frames.sh
executable file
·71 lines (57 loc) · 1.62 KB
/
hmdb_extract_frames.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
#!/bin/bash
if [ $# -lt 2 ]
then
echo "usage: $0 [input_dir] [output_dir] [quality=5 (2(best)-31(worst))]"
exit 1
fi
input_dir="$1"
output_dir="$2"
if [ $# -eq 2 ]
then
quality=5
else
quality="$3"
fi
mkdir -p "$output_dir"
bash_start_time=$(date +%s.%N)
index=1
videos=$(find "$1" -name "*.avi")
num_segments=$(echo "$videos" | wc -l)
num_errors=0
error_videos=""
while read line
do
echo $index / $num_segments
path_wo_ext="${line%.avi}"
frames_dir="${path_wo_ext/$input_dir/$output_dir}"
echo $frames_dir
mkdir -p "$frames_dir"
# -qscale:v : 1~31 where 31 is the worst quality
# when -qscale:v == 1, -qmin 1 need to be added
ffmpeg -i "$line" -start_number 0 -qscale:v "$quality" "$frames_dir/%05d.jpg" < /dev/null 2> /dev/null
RC=$?
if [ "${RC}" -ne "0" ]; then
# Do something to handle the error.
printf '\xF0\x9F\x98\xAD' # loudly crying face
echo " ERROR OCCURED WHILE PROCESSING THE VIDEO"
(( num_errors += 1 ))
error_videos="$error_videos$line\n"
fi
bash_end_time=$(date +%s.%N)
time_diff=$(echo "$bash_end_time - $bash_start_time" | bc)
average_time=$(echo "$time_diff / ($index)" | bc -l)
num_videos_left=$((num_segments - index))
eta=$(echo "$num_videos_left * ($average_time)" | bc -l)
printf "Average processing time per segment: %.2f, ETA: %.0f\n" "$average_time" "$eta"
(( index++ ))
done <<< "$videos"
if [ $num_errors -gt 0 ]
then
printf '\xF0\x9F\x98\xA1' # pouting face
echo " $num_errors errors occurred whilst extracting videos."
echo "Failed list:"
printf "$error_videos"
else
printf '\xF0\x9F\x98\x8D' # smiling face with heart-shaped eyes
echo " All videos successfully extracted"
fi