summaryrefslogblamecommitdiffstats
path: root/roles/prerec/templates/mux-subs.sh
blob: 87702ad221d99c158e3d4a172bcf69a7e4bd6e27 (plain) (tree)























                                                                                                                  
#!/usr/bin/env bash
# {{ ansible_managed }}
# Mixes in captions
# Usage: scripts/mux-subs.sh $video $vtt

set -euo pipefail

cleanup() {
    if [[ -v tmp_file ]]; then
        rm -f -- "$tmp_file"
    fi
}
trap cleanup EXIT

vid="$1"
sub="$2"

if head -1 "$sub" | grep -q -- captioned; then
    tmp_file="$(basename "$vid" ".webm")-new.webm"
    ffmpeg -y -i "$vid" -i "$sub" -c copy -metadata:s:s:0 language=eng -disposition:s:s:0 default "$tmp_file" && \
        mv "$tmp_file" "$vid"
else
    touch -m "$vid"
fi