test render script can cut without desync

This commit is contained in:
Dominic 2023-10-29 21:56:12 +01:00
parent 823d8ce5dc
commit ffad525857
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
2 changed files with 96 additions and 0 deletions

24
230101/setup.sh Executable file
View file

@ -0,0 +1,24 @@
#!/bin/busybox ash
set -euo pipefail
for i in 1 2 3; do rm "C0$i.svg" || true; rm "C0$i.mp4" || true; done
function write_svg() {
echo '<svg viewBox="0 0 1920 1080" width="1920" height="1080">'
echo ' <rect fill="'"$1"'" x="0" y="0" width="1920" height="1080"/>'
echo '</svg>'
}
write_svg blue >C01.svg
write_svg green >C02.svg
write_svg red >C03.svg
function render_svg() {
ffmpeg -hide_banner -vaapi_device /dev/dri/renderD128 \
-loop 1 -i "$1" \
-filter_complex "[0]format=nv12,hwupload[v];aevalsrc=sin($3*2*PI*t):s=48000[a]" \
-map "[v]" -map "[a]" \
-c:v h264_vaapi -r 25 -t 4 -b:a 128000 "$2"
}
for i in 1 2 3; do render_svg "C0$i.svg" "C0$i.mp4" $(($i*40+400)); done

72
230101/test_render.sh Executable file
View file

@ -0,0 +1,72 @@
#!/bin/busybox ash
set -euo pipefail
cd "$(dirname "$0")"
lecture=test_render
mkdir -p "$lecture"
rm "$lecture"/* || true
for file in *.mp4; do echo "file '$(realpath "$file")'" >>"$lecture/recording.txt"; done
function write_svg() {
echo '<svg viewBox="0 0 1920 1080" width="1920" height="1080">'
echo ' <rect fill="black" x="0" y="0" width="1920" height="1080"/>'
echo ' <text x="960" y="540" fill="white" text-anchor="middle" dominant-baseline="hanging" font-family="Noto Sans">'
echo " $1"
echo ' </text>'
echo '</svg>'
}
write_svg Intro >"$lecture/intro.svg"
write_svg Outro >"$lecture/outro.svg"
set -x
ffmpeg \
-hide_banner \
-f concat \
-safe 0 \
-i "$lecture/recording.txt" \
-af "pan=stereo|c0=c0|c1=c0,aformat=sample_rates=48000" \
-c:v copy -b:a 128000 \
"$lecture/recording.mp4"
ffmpeg \
-hide_banner \
-vaapi_device /dev/dri/renderD128 \
-loop 1 -i "$lecture/intro.svg" \
-filter_complex "[0]format=nv12,hwupload[v];aevalsrc=0:s=48000[a]" \
-map "[v]" -map "[a]" \
-c:v h264_vaapi -r 25 -t 3 -b:a 128000 \
"$lecture/intro.mp4"
ffmpeg \
-hide_banner \
-vaapi_device /dev/dri/renderD128 \
-loop 1 -i "$lecture/outro.svg" \
-filter_complex "[0]format=nv12,hwupload[v];aevalsrc=0:s=48000[a]" \
-map "[v]" -map "[a]" \
-c:v h264_vaapi -r 25 -t 5 -b:a 128000 \
"$lecture/outro.mp4"
ffmpeg \
-hide_banner \
-vaapi_device /dev/dri/renderD128 \
-i "$lecture/intro.mp4" \
-i "$lecture/recording.mp4" \
-i "$lecture/outro.mp4" \
-i "../assets/logo.svg" \
-i "../assets/fastforward.svg" \
-async 1 \
-filter_complex "
[1:v]trim=start=2:duration=8,setpts=PTS-STARTPTS[v_tmp0];
[1:a]atrim=start=2:duration=8,asetpts=PTS-STARTPTS[a_tmp0];
[0:v][0:a][v_tmp0][a_tmp0][2:v][2:a]concat=n=3:v=1:a=1[v_tmp1][a_tmp1];
[v_tmp1]format=nv12,hwupload[final_v];
[a_tmp1]anull[final_a]
" \
-map '[final_v]' -map '[final_a]' \
-c:v h264_vaapi -rc_mode CQP -global_quality 22 \
-c:a aac -b:a 128000 \
"$lecture/$lecture.mp4"