-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththumbnail.sh
executable file
·70 lines (61 loc) · 1.55 KB
/
thumbnail.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
#!/bin/bash
FORMATS=('*.mp4' '*.mkv' '*.avi' '*.m4v') # Let's figure out what format video files are in this directory
for ext in ${FORMATS[@]}; do
test=$(find . -maxdepth 1 -iname "$ext")
if [[ "$test" ]]; then
EXT+=("${ext}")
fi
done
SCALE="scale=640:-2"
Help() {
echo
echo "Create thumbnails for every video in afolder"
echo
echo "thumbnail [-h|t] [-f Filename]"
echo "options:"
echo "-h Show this help."
echo "-t Create thumbnail at a specific Timestamp. (ex. 00:00:05)"
echo "-f Filename to make a thumbnail for a single video."
echo
}
SetTimestamp() {
echo -n "Make thumbnail at what timestamp? (ex. 00:00:05) "
read TIMESTAMP
}
MakeThumbnail() {
for file in "$PWD"/"${EXT[@]}"; do
if [[ "$TIMESTAMP" ]]; then
TIME="-ss $TIMESTAMP"
VF="-vf $SCALE"
else
TIME=""
VF="-vf thumbnail,$SCALE"
fi
if [[ "$FILENAME" ]]; then
file="$FILENAME"
broked='True'
fi
echo "Creating thumbnail for ${file##*/}"
ffmpeg -hide_banner -loglevel error -i "$file" $TIME $VF -frames:v 1 "${file%%.mp4}"-thumb.jpg
if [[ "$broked" ]]; then
break
fi
done
}
while getopts ":htf:" option; do
case $option in
h)
Help
exit;;
t)
SetTimestamp
;;
f)
FILENAME="$OPTARG"
;;
?)
Help
exit;;
esac
done
MakeThumbnail