summaryrefslogtreecommitdiffstats
path: root/roles/prerec/templates/remux.sh
blob: c378133636da39820000e23d34b8c97ad6a12e36 (plain) (blame)
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
#!/usr/bin/env bash
# {{ ansible_managed }}
# Mix in the normalized audio
# Usage: remux.sh $input_video

with_suffix() {
    echo "$input_video" | sed "s/--\(reencoded\|original\).webm\$/--$1/"
}

input_video="$1"
input_audio="$(with_suffix "normalized.opus")"
output_video="$(with_suffix "final.webm")"
main_video="$(with_suffix "main.webm")"
main_subs="$(with_suffix "main.vtt")"

command="$(cat<<EOF
ffmpeg -i "$input_video" -i "$input_audio" -c:v copy -c:a copy -map 0:v:0 -map 1:a:0 "$output_video" &&
       cp "$output_video" "$main_video" &&
       if [[ -f "$main_subs" ]]; then touch -m "$main_subs"; fi
EOF
)"

printf "input: %s\ncomputed output: %s\nrelated main: %s\n\n" "$input_video" "$output_video" "$main_video"
printf "Produced incantation:\n%s\n\n" "$command"

while true;
do
    read -r -p "Run it?  y/n " -n 1 -r response
    if [[ $response =~ ^([yY])$ ]]; then
        eval "$command"
        exit 0
    else
        printf "\nExiting\n"
        exit 3
    fi
done