-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfliese-miniaturansichten
executable file
·184 lines (151 loc) · 6.13 KB
/
fliese-miniaturansichten
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/sh
#===============================================================================
# tile-thumbnails
# fliese-miniaturansichten
# Erstellen Sie ein Bild mit Miniaturansichten aus einem Video
#===============================================================================
# Abhängigkeiten:
# ffmpeg ffprobe awk bc
#===============================================================================
# Verwendung von Skripten
#===============================================================================
usage()
{
echo "\
# Erstellen Sie ein Bild mit Miniaturansichten aus einem Video
$(basename "$0") -i eingang -s 00:00:00.000 -w 000 -t 0x0 -p 00 -m 00 -c farbe -f Schriftfarbe -b Kastenfarbe -x on -o ausgang.png
-i eingang.(mp4|mkv|mov|m4v|webm)
-s Suchen Sie in der Videodatei : Standard 00:00:05
-w Thumbnail-Breite : 160
-t Fliese layout format breite x höhe : Standard 4x3
-p Polsterung zwischen Bildern : Standard 7
-m Rand : Standard 2
-c Farbe = https://ffmpeg.org/ffmpeg-utils.html#color-syntax : Standard black
-f Schriftfarbe : Standardmäßig weiß
-b Kastenfarbe : Standardmäßig schwarz
-x on : Standardmäßig deaktiviert, Zeitstempel anzeigen
-o ausgang.png :optionales Argument
# Wenn die Option nicht bereitgestellt wird, wird standardmäßig Eingabename-Kachel-Datum-Uhrzeit.png verwendet"
exit 2
}
#===============================================================================
# error messages
#===============================================================================
INVALID_OPT_ERR='Ungültige Option:'
REQ_ARG_ERR='erfordert eine Argumentation'
WRONG_ARGS_ERR='falsche Anzahl von Argumenten an Skript übergeben'
#===============================================================================
# Überprüfen Sie die Anzahl der an das Skript übergebenen Argumente
#===============================================================================
[ $# -gt 0 ] || usage "${WRONG_ARGS_ERR}"
#===============================================================================
# getopts überprüft die an das Skript übergebenen Optionen
#===============================================================================
while getopts ':i:s:w:t:p:m:c:b:f:x:o:h' opt
do
case ${opt} in
i) infile="${OPTARG}";;
s) seek="${OPTARG}";;
w) scale="${OPTARG}";;
t) tile="${OPTARG}";;
p) padding="${OPTARG}";;
m) margin="${OPTARG}";;
c) color="${OPTARG}";;
f) fontcolor="${OPTARG}";;
b) boxcolor="${OPTARG}";;
x) timestamp="${OPTARG}";;
o) outfile="${OPTARG}";;
h) usage;;
\?) usage "${INVALID_OPT_ERR} ${OPTARG}" 1>&2;;
:) usage "${INVALID_OPT_ERR} ${OPTARG} ${REQ_ARG_ERR}" 1>&2;;
esac
done
shift $((OPTIND-1))
#===============================================================================
# variablen
#===============================================================================
# Eingabe, Eingabename
infile_nopath="${infile##*/}"
infile_name="${infile_nopath%.*}"
# ffprobe erhält fps und Dauer
videostats=$(ffprobe \
-v error \
-select_streams v:0 \
-show_entries stream=r_frame_rate:format=duration \
-of default=noprint_wrappers=1 \
"${infile}")
# fps
fps=$(echo "${videostats}" | awk -F'[=//]' '/r_frame_rate/{print $2/$3}')
# Dauer
duration=$(echo "${videostats}" | awk -F'[=/.]' '/duration/{print $2}')
# Überprüfen Sie, ob die Kachel null ist
if [ -z "${tile}" ]; then
: # Tile-Variable nicht gesetzt : = pass
else
# Tile-Variablensatz
# Fliesenlayout
tile_w=$(echo "${tile}" | awk -F'x' '{print $1}')
tile_h=$(echo "${tile}" | awk -F'x' '{print $2}')
# Titelsumme
tile_sum=$(echo "${tile_w} * ${tile_h}" | bc)
fi
# Voreinstellungen
seek_default='00:00:05'
scale_default='160'
tile_layout_default='4x3'
tile_default='12'
padding_default='7'
margin_default='2'
color_default='black'
fontcolor_default='white'
boxcolor_default='black'
timestamp_default='off'
pts_default='5'
pts=$(printf "%s %s\n" "${seek}" | awk '{
start = $1
if (start ~ /:/) {
split(start, t, ":")
seconds = (t[1] * 3600) + (t[2] * 60) + t[3]
}
printf("%s\n"), seconds
}')
outfile_default="${infile_name}-fliese-$(date +"%Y-%m-%d-%H-%M-%S").png"
# Dauer * fps / Anzahl der Kacheln
frames=$(echo "${duration} * ${fps} / ${tile_sum:=${tile_default}}" | bc)
#===============================================================================
# Funktionen
#===============================================================================
# Kontaktabzug – keine Zeitstempel
tilevideo () {
ffmpeg \
-hide_banner \
-stats -v panic \
-ss "${seek:=${seek_default}}" \
-i "${infile}" \
-frames 1 -vf "select=not(mod(n\,${frames})),scale=${scale:=${scale_default}}:-1,tile=${tile:=${tile_layout_default}}:padding=${padding:=${padding_default}}:margin=${margin:=${margin_default}}:color=${color:=${color_default}}" \
"${outfile:=${outfile_default}}"
}
# Kontaktabzug - Zeitstempel
timestamp () {
ffmpeg \
-hide_banner \
-stats -v panic \
-ss "${seek:=${seek_default}}" \
-i "${infile}" \
-frames 1 -vf "drawtext=text='%{pts\:hms\:${pts:=${pts_default}}}':x='(main_w-text_w)/2':y='(main_h-text_h)':fontcolor=${fontcolor:=${fontcolor_default}}:fontsize='(main_h/8)':boxcolor=${boxcolor:=${boxcolor_default}}:box=1,select=not(mod(n\,${frames})),scale=${scale:=${scale_default}}:-1,tile=${tile:=${tile_layout_default}}:padding=${padding:=${padding_default}}:margin=${margin:=${margin_default}}:color=${color:=${color_default}}" \
"${outfile:=${outfile_default}}"
}
#===============================================================================
# Prüfoption, die an das Skript übergeben wird
#===============================================================================
if [ "${timestamp}" == on ]; then
timestamp "${infile}" # -x on
elif [ ! -z "${fontcolor}" ]; then
timestamp "${infile}" # -f
elif [ ! -z "${boxcolor}" ]; then
timestamp "${infile}" # -b
elif [ -z "${timestamp}" ]; then
tilevideo "${infile}" # kein Zeitstempel
else
tilevideo "${infile}" # kein Zeitstempel
fi