-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkthumbs.sh
executable file
·90 lines (86 loc) · 2.23 KB
/
mkthumbs.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
#!/bin/sh
#
# mkthumbs.sh - make thumbnails for available videos
#
# This file is part of TiCijev.
#
# TiCijev is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# TiCijev is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with TiCijev. If not, see <http://www.gnu.org/licenses/>.
#
VDIR='videos'
#
# Default option values
#
force='no'
verbose='no'
#
# Handle options
#
while echo "$1" | grep '^-' >/dev/null; do
#
# Force overwriting of existing files?
#
if [ "$1" = '-f' -o "$1" = '--force' ]; then
force='yes'
fi
#
# Verbose output (warnings etc.)?
#
if [ "$1" = '-v' -o "$1" = '--verbose' ]; then
verbose='yes'
fi
shift
done
#
# Find all video files and make thumbnails for them
#
find "$VDIR" \( -name '*.mp4' -o -name '*.webm' \) \
| while read video; do
#
# Determine the length of the video
#
len=$(
ffprobe \
-v error \
-select_streams v:0 \
-show_entries format=duration \
-of default=noprint_wrappers=1:nokey=1 \
"$video"
)
#
# Note the middle position of the video
#
pos=$(awk 'BEGIN { print ARGV[1] / 2.0 }' "$len")
#
# Generate the thumbnail from the middle of the video
#
thumb="$(dirname "$video")/thumb.jpg"
if [ -f "$thumb" -a "$force" = 'no' ]; then
if [ "$verbose" = 'yes' ]; then
echo "WARNING: Not overwriting '$thumb'" >&2
fi
continue
fi
#
# Generate thumbnail
#
if [ "$verbose" = 'yes' ]; then
echo "Generating thumbnail '$thumb'" >&2
fi
#
# Need to close stdin so ffmpeg doesn't
# interfere with our while-read loop!!!
#
ffmpeg -y -v quiet -ss "$pos" -i "$video" \
-vframes 1 -s 280x156 -f image2 "$thumb" </dev/null
done