From 0963815d6bb6e9cf01b95aa05c3b34a3d6fcaa22 Mon Sep 17 00:00:00 2001 From: Sacha Chua Date: Tue, 17 Oct 2023 11:59:28 -0400 Subject: add prerec scripts --- roles/prerec/templates/Makefile | 13 ++++ roles/prerec/templates/mux-subs.sh | 24 +++++++ roles/prerec/templates/remux.sh | 36 ++++++++++ roles/prerec/templates/rename-original.sh | 15 +++- roles/prerec/templates/verify-main.sh | 115 ++++++++++++++++++++++++++++++ 5 files changed, 201 insertions(+), 2 deletions(-) create mode 100644 roles/prerec/templates/Makefile create mode 100755 roles/prerec/templates/mux-subs.sh create mode 100755 roles/prerec/templates/remux.sh create mode 100755 roles/prerec/templates/verify-main.sh (limited to 'roles/prerec/templates') diff --git a/roles/prerec/templates/Makefile b/roles/prerec/templates/Makefile new file mode 100644 index 0000000..53b49be --- /dev/null +++ b/roles/prerec/templates/Makefile @@ -0,0 +1,13 @@ +# {{ ansible_managed }} + +PRERECS_FINAL := $(wildcard {{ emacsconf_id }}-*--final.webm) +PRERECS_MAIN := $(patsubst %--final.webm, %--main.webm, $(PRERECS_FINAL)) + +.PHONY: all +all: $(PRERECS_MAIN) $(PRERECS_FINAL) + +emacsconf-%--main.webm: {{ emacsconf_id }}-%--final.webm + cp "$<" "$@" + +emacsconf-%--final.webm: {{ emacsconf_id }}-%--main.vtt + mux-subs.sh "$@" "$<" diff --git a/roles/prerec/templates/mux-subs.sh b/roles/prerec/templates/mux-subs.sh new file mode 100755 index 0000000..87702ad --- /dev/null +++ b/roles/prerec/templates/mux-subs.sh @@ -0,0 +1,24 @@ +#!/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 diff --git a/roles/prerec/templates/remux.sh b/roles/prerec/templates/remux.sh new file mode 100755 index 0000000..c378133 --- /dev/null +++ b/roles/prerec/templates/remux.sh @@ -0,0 +1,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<