-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuberzug-pip
executable file
·181 lines (147 loc) · 5.85 KB
/
uberzug-pip
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
#!/bin/sh
#===============================================================================
# overlay-pip
# uberzug-pip
# Erstellen Sie ein Bild-in-Bild-Video
#===============================================================================
# Abhängigkeiten:
# ffmpeg ffprobe cut bc
#===============================================================================
# Verwendung von Skripten
#===============================================================================
usage()
{
# Wenn das Argument an die Funktion übergeben wird, echo es
[ -z "${1}" ] || echo "! ${1}"
# Hilfe anzeigen
# display help
echo "\
# Erstellen Sie ein Bild-in-Bild-Video
$(basename "$0") -i eingang.(mp4|mkv|mov|m4v) -v eingang.(mp4|mkv|mov|m4v) -p [0-999]
-m [00] -x (tl|tr|bl|br) -w [000] -f (0.1-9|1) -b [00] -c colour -o ausgang.mp4
-i eingang.(mp4|mkv|mov|m4v) : unteres Video
-v eingang.(mp4|mkv|mov|m4v) : Video überlagern
-p [0-999] : Zeit, um das Video zu überlagern
-m [00] : Rand ist standardmäßig 0
-x (tl|tr|bl|br) : Pip-Position - standardmäßig tr
-w [000] : width - standardmäßig 1/4 der Videogröße
-f (0.1-9|1) : Fade von 0,1 auf 1 - Standardeinstellung 0,2
-b [00] : Grenze
-c colour : Farbe
-o ausgang.mp4 : Optionales Argument # Wenn die Option nicht bereitgestellt wird,
wird standardmäßig Eingabename-Pip-Datum-Uhrzeit verwendet"
exit 2
}
#===============================================================================
# Fehlermeldungen
#===============================================================================
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:v:p:m:x:w:f:c:b:o:h' opt
do
case ${opt} in
i) video="${OPTARG}";;
v) overlay="${OPTARG}";;
p) position="${OPTARG}";;
m) margin="${OPTARG}";;
x) pip="${OPTARG}"
case "${pip}" in
tl|tr|bl|br);;
*) usage "${pip} ${INVALID_OPT_ERR}";;
esac;;
w) width="${OPTARG}";;
f) fade="${OPTARG}";;
c) colour="${OPTARG}";;
b) border="${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
#===============================================================================
# Videonamenerweiterung und Overlay-Videoerweiterungen
video_nopath="${video##*/}"
video_name="${video_nopath%.*}"
# Standardwerte für Variablen, falls nicht definiert
outfile_default="${video_name}-pip-$(date +"%Y-%m-%d-%H-%M-%S").mp4"
#===============================================================================
# Funktionen
#===============================================================================
# Overlay-Video-Funktion
overlay_video () {
ffmpeg \
-hide_banner \
-stats -v panic \
-i "${video}" \
-i "${overlay}" \
-filter_complex \
"[0:0]setpts=PTS-STARTPTS[firstclip];
[1:0]setpts=PTS+${position}/TB[secondclip];
[firstclip][secondclip]overlay=enable='between(t\,${position},${dp})'[ov];
[0:0]scale=${width_scale:=${width_default}}${draw_border}[pip];
[pip]format=pix_fmts=yuva420p,fade=t=in:st=${position}:d=${fade:=${fade_default}}:alpha=1,fade=t=out:st=${fade_end}:d=${fade:=${fade_default}}:alpha=1[pipfade];
[ov][pipfade]overlay=${pip:=${pip_default}}:enable='between(t\,${position},${dp})'[pv]" \
-map "[pv]" -map 0:1 \
-pix_fmt yuv420p \
-c:a copy -c:v libx264 -crf 18 \
-movflags +faststart \
-f mp4 \
"${outfile:=${outfile_default}}"
}
# Holen Sie sich die Dauer von Overlay-Videos mit ffprobe
duration="$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "${overlay}" | cut -d\. -f1)"
# Position + Dauer
dp="$((position+duration))"
# Fade-Standard
fade_default='0.2'
fade_end="$(echo "${dp}" - "${fade:=${fade_default}}" | bc)"
# Pip-Polsterung
margin_default='20'
# Pip-Standardposition
pip_default="${tr}"
# Pip-Position
tl="${margin:=${margin_default}}:${margin:=${margin_default}}"
tr="main_w-overlay_w-${margin:=${margin_default}}:${margin:=${margin_default}}"
bl="${margin:=${margin_default}}:main_h-overlay_h-${margin:=${margin_default}}"
br="main_w-overlay_w-${margin:=${margin_default}}:main_h-overlay_h-${margin:=${margin_default}}"
# Pip-Fenstergröße
width_default='iw/4:ih/4'
# prüfen, ob width null und nicht gesetzt ist
if [ -z "${width}" ]; then
: # Breite nicht eingestellt pass
else
width_scale="${width}:-1"
fi
# Grenze
# dividieren Sie die Grenze durch 2 für den Versatz
border_default='4'
offset_default='2'
colour_default='#2f2f2f'
offset="$((${border:=${border_default}}/2))"
draw_border=",pad=w=${border:=${border_default}}+iw:h=${border:=${border_default}}+ih:x=${offset:=${offset_default}}:y=${offset:=${offset_default}}:color=${colour:=${colour_default}}"
# Rand des auf 0 gesetzten Randes nicht anzeigen
if [ "${border}" = 0 ]; then
draw_border=''
fi
# Pip-Position-Fall
case "${pip}" in
tl)pip="${tl}";;
tr)pip="${tr}";;
bl)pip="${bl}";;
br)pip="${br}";;
*) pip="${tr}";;
esac
# Führen Sie die Funktion overlay_video aus
overlay_video "${video}" "${overlay}"