# test script for webinar-to-shorts-and-carousel (sections for the other page in the same run are included; see fixlog part at the end)
#!/bin/bash
# Batch tests 2026-11-21: screen recording crop, webinar piece cut, voice memo clean-up. ffmpeg 6.1.1 on the hub server.
set -u
F=/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf
probe(){ ffprobe -v error -show_entries stream=codec_name,width,height,r_frame_rate,channels,sample_rate:format=duration,size -of default=nw=1 "$1" | tr "\n" " "; echo; }
run(){ echo "published: $*"; local t0=$(date +%s.%N); eval "$* -y -hide_banner -loglevel error"; local rc=$?; echo "exit=$rc time=$(echo "$(date +%s.%N)-$t0" | bc | cut -c1-5)s"; }
############ A screen recording
############ B webinar
{
echo "# webinar piece cut: commands.log (2026-11-21, ffmpeg 6.1.1)"
if [ ! -f webinar-model.mp4 ]; then t0=$(date +%s); ffmpeg -y -hide_banner -loglevel error -f lavfi -i "testsrc2=s=1280x720:r=25:d=2700" -f lavfi -i "sine=f=180:d=2700" -vf "drawtext=fontfile=$F:textfile=clock.txt:x=40:y=40:fontsize=48:fontcolor=white:box=1:boxcolor=black" -c:v libx264 -preset veryfast -crf 26 -g 250 -pix_fmt yuv420p -c:a aac -b:a 96k webinar-model.mp4; echo "model file encoded in $(( $(date +%s)-t0 )) s"; fi
echo "test file: webinar-model.mp4 (constructed: 45 min test pattern with a burned clock, 1280x720, 25 fps, keyframe every 10 s, tone)"; probe webinar-model.mp4; ls -l webinar-model.mp4 | awk "{print \"bytes \"\$5}"
echo; echo "## 1. cut a piece without re-encoding"
run "ffmpeg -ss 00:12:34 -i webinar-model.mp4 -t 90 -c copy piece.mp4"; probe piece.mp4
echo "first video frame of piece.mp4 shows clock:"; ffmpeg -hide_banner -loglevel error -y -i piece.mp4 -frames:v 1 first.png; ffprobe -v error -select_streams v:0 -show_entries packet=pts_time,flags -of csv=p=0 piece.mp4 | head -3
ffprobe -v error -select_streams v:0 -show_entries stream=start_time -of default=nw=1 piece.mp4
echo "edge: start 00:12:30 (on a keyframe)"
run "ffmpeg -ss 00:12:30 -i webinar-model.mp4 -t 90 -c copy piece-key.mp4"; probe piece-key.mp4; ffprobe -v error -select_streams v:0 -show_entries stream=start_time -of default=nw=1 piece-key.mp4
echo; echo "## 2. frame-accurate cut with re-encoding"
run "ffmpeg -ss 00:12:34 -i webinar-model.mp4 -t 90 -c:v libx264 -crf 20 -c:a aac piece-exact.mp4"; probe piece-exact.mp4; ffprobe -v error -select_streams v:0 -show_entries stream=start_time -of default=nw=1 piece-exact.mp4
echo "edge: piece that runs past the end of the file (start 44:30, 90 s asked)"
run "ffmpeg -ss 00:44:30 -i webinar-model.mp4 -t 90 -c:v libx264 -crf 20 -c:a aac piece-end.mp4"; probe piece-end.mp4
} > webinar.log 2>&1
############ C voice memo
{
echo "# voice memo clean-up: commands.log (2026-11-21, ffmpeg 6.1.1)"
T1="I had an idea on the walk home. Most tutorials start with the tool. Start with the mistake instead."
T2="Show the wrong result first. Then fix it in three steps. People remember the fix when they have seen the problem."
ffmpeg -y -hide_banner -loglevel error -f lavfi -i "flite=text=$T1:voice=slt" a.wav; ffmpeg -y -hide_banner -loglevel error -f lavfi -i "flite=text=$T2:voice=slt" b.wav
ffmpeg -y -hide_banner -loglevel error -f lavfi -t 2.5 -i anullsrc=r=16000:cl=mono -i a.wav -f lavfi -t 4 -i anullsrc=r=16000:cl=mono -i b.wav -f lavfi -t 3 -i anullsrc=r=16000:cl=mono -filter_complex "[0][1][2][3][4]concat=n=5:v=0:a=1,volume=0.25,aresample=48000[a];anoisesrc=d=60:c=pink:a=0.002:r=48000[n];[a][n]amix=inputs=2:duration=first:normalize=0" -c:a aac -b:a 64k -ac 1 memo.m4a
echo "test file: memo.m4a (synthetic voice reading our own text, quiet, with 2.5 s, 4 s and 3 s pauses and faint pink noise; mono AAC)"; probe memo.m4a
echo "loudness before:"; ffmpeg -hide_banner -nostats -i memo.m4a -af ebur128=framelog=quiet -f null - 2>&1 | grep -E "I:|LRA:" | head -2
echo; echo "## 1. cut pauses longer than one second and bring loudness to -16 LUFS"
run "ffmpeg -i memo.m4a -af \"silenceremove=stop_periods=-1:stop_duration=1:stop_threshold=-40dB:start_periods=1:start_threshold=-40dB,loudnorm=I=-16:TP=-1.5:LRA=11\" -ar 48000 -c:a aac -b:a 128k memo-clean.m4a"; probe memo-clean.m4a
echo "loudness after:"; ffmpeg -hide_banner -nostats -i memo-clean.m4a -af ebur128=framelog=quiet -f null - 2>&1 | grep -E "I:|LRA:" | head -2
echo "edge: a memo with no pauses and normal level (b.wav only), same command"
ffmpeg -y -hide_banner -loglevel error -i b.wav -c:a aac -b:a 64k edge.m4a; probe edge.m4a
run "ffmpeg -i edge.m4a -af \"silenceremove=stop_periods=-1:stop_duration=1:stop_threshold=-40dB:start_periods=1:start_threshold=-40dB,loudnorm=I=-16:TP=-1.5:LRA=11\" -ar 48000 -c:a aac -b:a 128k edge-clean.m4a"; probe edge-clean.m4a
echo "loudness edge before/after:"; for f in edge.m4a edge-clean.m4a; do ffmpeg -hide_banner -nostats -i $f -af ebur128=framelog=quiet -f null - 2>&1 | grep -E "I:" | head -1; done
echo; echo "## 2. still picture plus the memo = a vertical video"
ffmpeg -y -hide_banner -loglevel error -f lavfi -i "color=c=0x101828:s=1080x1920:d=1" -frames:v 1 cover.png
run "ffmpeg -loop 1 -i cover.png -i memo-clean.m4a -c:v libx264 -tune stillimage -r 30 -pix_fmt yuv420p -c:a copy -shortest memo-video.mp4"; probe memo-video.mp4
echo "edge: cover with an odd size (1081x1921)"; ffmpeg -y -hide_banner -loglevel error -f lavfi -i "color=c=0x101828:s=1081x1921:d=1" -frames:v 1 cover-odd.png
run "ffmpeg -loop 1 -i cover-odd.png -i memo-clean.m4a -c:v libx264 -tune stillimage -r 30 -pix_fmt yuv420p -c:a copy -shortest edge-video.mp4"; probe edge-video.mp4 2>&1 | head -2
} > memo.log 2>&1
echo DONE
# ---- follow-up checks
cd ~/b1-work
probe(){ ffprobe -v error -show_entries stream=codec_name,width,height,r_frame_rate,channels,sample_rate:format=duration,size -of default=nw=1 "$1" | tr "\n" " "; echo; }
run(){ echo "published: $*"; local t0=$(date +%s.%N); eval "$* -y -hide_banner -loglevel error"; local rc=$?; echo "exit=$rc time=$(echo "$(date +%s.%N)-$t0" | bc | cut -c1-5)s"; }
sed -i '/^## 2. still picture plus the memo/,$d' memo.log
{
echo "## 2. still picture plus the memo = a vertical video"
run "ffmpeg -loop 1 -i cover.png -i memo-clean.m4a -vf \"scale=trunc(iw/2)*2:trunc(ih/2)*2\" -c:v libx264 -tune stillimage -r 30 -pix_fmt yuv420p -c:a copy -shortest memo-video.mp4"; probe memo-video.mp4
echo "edge: cover with an odd size (1081x1921), same command"
run "ffmpeg -loop 1 -i cover-odd.png -i memo-clean.m4a -vf \"scale=trunc(iw/2)*2:trunc(ih/2)*2\" -c:v libx264 -tune stillimage -r 30 -pix_fmt yuv420p -c:a copy -shortest edge-video.mp4"; probe edge-video.mp4
echo "edge: the same odd cover WITHOUT the scale filter (not published; shows why the filter is there)"
ffmpeg -loop 1 -i cover-odd.png -i memo-clean.m4a -c:v libx264 -tune stillimage -r 30 -pix_fmt yuv420p -c:a copy -shortest edge-fail.mp4 -y -hide_banner -loglevel error 2>&1 | head -1; echo "exit=${PIPESTATUS[0]}"
} >> memo.log 2>&1
{
echo; echo "## 3. what is inside the stream-copied piece (piece.mp4, asked to start at 00:12:34)"
echo "duration read normally: $(ffprobe -v error -show_entries format=duration -of csv=p=0 piece.mp4) s"
echo "duration with the edit list ignored (-ignore_editlist 1): $(ffprobe -v error -ignore_editlist 1 -show_entries format=duration -of csv=p=0 piece.mp4) s"
echo "first frame read normally shows the burned clock 00:12:34.000; with the edit list ignored it shows 00:12:30.000 (frames saved as f-default.png and f-noedit.png and read by eye)"
echo "size per minute of this model file: $(python3 -c "print(round(666647343/45/1e6,1))") MB; a 100 MB piece holds $(python3 -c "print(round(100/(666647343/45/1e6),1))") min"
} >> webinar.log
tail -8 memo.log | cut -c1-200; tail -5 webinar.log
