-
Notifications
You must be signed in to change notification settings - Fork 0
/
6_add_intro_outro.sh
executable file
·55 lines (48 loc) · 1.56 KB
/
6_add_intro_outro.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
#!/bin/bash
. settings.env
for video_dir in $WORKING_DIR/*/ ;
do
if [ ! -f ${video_dir}${PREFIX}combined.mp4 ]; then
echo "Skipping $video_dir, no ${PREFIX}combined.mp4";
continue
fi
if [ ! -f ${video_dir}intro.mp4 ]; then
echo "Skipping $video_dir, no intro.mp4";
continue
fi
transition_duration=500
if [ -f ${video_dir}${PREFIX}transitioned.mp4 ]; then
read -p "File '${video_dir}${PREFIX}transitioned.mp4' already exists. Overwrite ? [y/N] " overwrite
fi
if [ ! -f ${video_dir}${PREFIX}transitioned.mp4 ] || [[ $overwrite =~ [yY] ]]; then
ffmpeg-concat \
-d ${transition_duration} \
-o ${video_dir}${PREFIX}transitioned.mp4 \
${video_dir}intro.mp4 \
${video_dir}${PREFIX}combined.mp4 \
$WORKING_DIR/outro.mp4
fi
intro_length=$(ffprobe \
-v error \
-show_entries stream=duration \
-of default=noprint_wrappers=1:nokey=1 \
${video_dir}intro.mp4)
offset=$(echo "$intro_length * 1000 - $transition_duration" | bc)
# ffmpeg-concat removes the audio, so copy it back:
ffmpeg \
-y \
-i ${video_dir}${PREFIX}transitioned.mp4 \
-vn -i ${video_dir}${PREFIX}combined.mp4 \
-i ${WORKING_DIR}/intro.wav \
-filter_complex \
"
[1:a]
adelay=$offset|$offset
[delayed];
[2:a] [delayed] amix [mixed_audio]
"\
-c:v copy \
-map 0:v \
-map '[mixed_audio]' \
${video_dir}${PREFIX}output.mp4
done