render_video/230101/test_render.sh

95 lines
3.1 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 "loudnorm,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"
#convert -background none -density 1000 -resize 150x ../assets/logo.svg "$lecture/logo.png"
#convert -background none -density 1000 -resize 128x ../assets/fastforward.svg "$lecture/fastforward.png"
inkscape -w 150 -h 150 ../assets/logo.svg -o "$lecture/logo.png"
inkscape -w 128 -h 128 ../assets/fastforward.svg -o "$lecture/fastforward.png"
ffmpeg \
-hide_banner \
-vaapi_device /dev/dri/renderD128 \
-i "$lecture/intro.mp4" \
-i "$lecture/recording.mp4" \
-i "$lecture/outro.mp4" \
-i "$lecture/logo.png" \
-i "$lecture/fastforward.png" \
-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];
[v_tmp0]split=3[t0_v_tmp1][t1_v_tmp1][t2_v_tmp1];
[t0_v_tmp1]trim=duration=3[t3_v_tmp1];
[t1_v_tmp1]trim=start=3:duration=2,setpts=PTS-STARTPTS,setpts=PTS/3[t4_v_tmp1];
[t4_v_tmp1][4]overlay=x=main_w/2-overlay_w/2:y=main_h/2-overlay_h/2[t6_v_tmp1];
[t2_v_tmp1]trim=start=5,setpts=PTS-STARTPTS[t5_v_tmp1];
[a_tmp0]asplit=3[t0_a_tmp1][t1_a_tmp1][t2_a_tmp1];
[t0_a_tmp1]atrim=duration=3[t3_a_tmp1];
[t1_a_tmp1]atrim=start=3:duration=2,asetpts=PTS-STARTPTS,atempo=3[t4_a_tmp1];
[t2_a_tmp1]atrim=start=5,asetpts=PTS-STARTPTS[t5_a_tmp1];
[t3_v_tmp1][t3_a_tmp1][t6_v_tmp1][t4_a_tmp1][t5_v_tmp1][t5_a_tmp1]concat=n=3:v=1:a=1[v_tmp1][a_tmp1];
[0:v][0:a][v_tmp1][a_tmp1][2:v][2:a]concat=n=3:v=1:a=1[v_tmp2][a_tmp2];
[3]format=yuva444p,colorchannelmixer=aa=0.5[logo];
[v_tmp2][logo]overlay=x=main_w-overlay_w-130:y=main_h-overlay_h-65[v_tmp3];
[a_tmp2]anull[a_tmp3];
[v_tmp3]format=nv12,hwupload[final_v];
[a_tmp3]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"