render_video/230101/test_render.sh

72 lines
1.9 KiB
Bash
Executable file

#!/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"