Last active
February 21, 2024 13:43
-
-
Save matiaspl/f9122d21ef2137b0c29dcf86ee8db505 to your computer and use it in GitHub Desktop.
moving bar testcard generator for synchronization testing based on timestamps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
fps=25 | |
delay=2 | |
width=640 | |
height=360 | |
bar_width=20 | |
bar_height=$((height / 2)) | |
bar_speed=4 | |
streams=( | |
##ACTIVE | |
"srt://stream1:1234" | |
"srt://stream1:1234" | |
"srt://stream1:1234" | |
##TEST | |
#"srt://some_unused_stream" | |
#"srt://some_other_unused_stream" | |
) | |
colors=( | |
"white" | |
"yellow" | |
"cyan" | |
"green" | |
"magenta" | |
"red" | |
"blue" | |
) | |
font="/usr/share/fonts/truetype/noto/NotoMono-Regular.ttf" | |
fontsize=24 | |
text1="\'TELLYO TS SYNC" | |
text2="%{eif\:mod(n\,1000)\:d:3}\'" | |
#%{localtime\:%T}\'" | |
on_die () | |
{ | |
# kill all children | |
pkill -KILL -P $$ | |
} | |
trap 'on_die' TERM | |
for i in "${!streams[@]}" | |
do | |
frequency=$(awk "BEGIN { printf \"%.2f\", 220 * (2 ^ (1/3)) ^ $i }") | |
j=$((i+1)) | |
text="$text1 $j $text2 +$((i*delay))s" | |
echo "Running $j to ${streams[$i]}" | |
/apps/ffmpeg/bin/ffmpeg -loglevel 0 -hide_banner -re -f lavfi -i color=s=${width}x${height}:rate=$fps \ | |
-f lavfi -i sine=$frequency:r=48000 \ | |
-filter_complex "color=${colors[$i % 7]}:size=${bar_width}x${bar_height}:d=1[c]; \ | |
[0:v][c]overlay=x='mod(n*${bar_speed},${width})',drawtext=fontfile=${font}:fontsize=${fontsize}:line_spacing=15:box=1:[email protected]:boxborderw=5:fontcolor=white:x=(w-text_w)/2:y=((40)/2):text=${text}" \ | |
-c:v h264 -tune:v zerolatency -profile:v baseline -pix_fmt yuv420p -preset:v ultrafast -force_key_frames 'expr:gte(t,n_forced*2)' -sc_threshold 0 -crf 22 -ac 2 -c:a aac -map_metadata -1 -f mpegts ${streams[$i % 7]} & | |
sleep $delay | |
done | |
wait |
Author
matiaspl
commented
Feb 21, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment