Loop file and generate multiple video bitrates muxed in MPEG-TS with ffmpeg

ffmpeg -stream_loop -1 -i /mnt/Sunrise.mp4 -map 0:v -vcodec copy -bsf:v h264_mp4toannexb -f h264 - | ffmpeg -framerate 25 -fflags +genpts -r 25 -re -i - -f lavfi -i anullsrc=r=48000:cl=stereo -c:a aac -shortest -vf drawtext=fontfile=/root/Vera.ttf:fontsize=12:text='eyevinntechnology/toolbox-loopts':fontcolor=white@0.9:x=20:y=20:shadowcolor=black:shadowx=2:shadowy=1,drawtext=fontfile=/root/Vera.ttf:fontsize=200:text='%{localtime\:%T}':fontcolor=white@0.9:x=(w-tw)/2:y=250:shadowcolor=black:shadowx=2:shadowy=1,drawtext=fontfile=/root/Vera.ttf:fontsize=40:text='[%{n}/%{pts}]':fontcolor=white@0.9:x=(w-tw)/2:y=h-th-10:shadowcolor=black:shadowx=2:shadowy=1 -vcodec libx264 -preset veryfast -pix_fmt yuv420p -strict -2 -y -f mpegts -r 25 udp://239.0.0.1:1234?pkt_size=1316
ffmpeg -stream_loop -1 -i /mnt/Sunrise.mp4 -map 0:v -vcodec copy -bsf:v h264_mp4toannexb -f h264 - | ffmpeg -thread_queue_size 512 -threads 4 -framerate 25 -fflags +genpts -r 25 -re -i - -f lavfi -i anullsrc=r=48000:cl=stereo -filter_complex [0:v]drawtext=fontfile=/root/Vera.ttf:fontsize=12:text='eyevinntechnology/toolbox-loopts':fontcolor=white@0.9:x=20:y=20:shadowcolor=black:shadowx=2:shadowy=1,drawtext=fontfile=/root/Vera.ttf:fontsize=200:text='%{localtime\:%T}':fontcolor=white@0.9:x=(w-tw)/2:y=250:shadowcolor=black:shadowx=2:shadowy=1,drawtext=fontfile=/root/Vera.ttf:fontsize=40:text='[%{n}/%{pts}]':fontcolor=white@0.9:x=(w-tw)/2:y=h-th-10:shadowcolor=black:shadowx=2:shadowy=1[overlay];[overlay]split=4[o1][o2][o3][o4];[o1]scale=480:360,drawtext=fontfile=/root/Vera.ttf:fontsize=12:text='480x360':fontcolor=white@0.9:x=(w-tw)/2:y=20:shadowcolor=black:shadowx=2:shadowy=1[out360];[o2]scale=854:480,drawtext=fontfile=/root/Vera.ttf:fontsize=12:text='854x480':fontcolor=white@0.9:x=(w-tw)/2:y=20:shadowcolor=black:shadowx=2:shadowy=1[out480];[o3]scale=1280:720,drawtext=fontfile=/root/Vera.ttf:fontsize=12:text='1280x720':fontcolor=white@0.9:x=(w-tw)/2:y=20:shadowcolor=black:shadowx=2:shadowy=1[out720];[o4]scale=1920:1080,drawtext=fontfile=/root/Vera.ttf:fontsize=12:text='1920x1080':fontcolor=white@0.9:x=(w-tw)/2:y=20:shadowcolor=black:shadowx=2:shadowy=1[out1080] -map [out360] -map 1:0 -map [out480] -map [out720] -map [out1080] -c:a aac -shortest -c:v:0 libx264 -preset veryfast -pix_fmt yuv420p -g 50.0 -keyint_min 50.0 -force_key_frames expr:gte(t,n_forced*2) -b:v:0 400k -maxrate 400k -bufsize 16.0k -c:v:1 libx264 -preset veryfast -pix_fmt yuv420p -g 50.0 -keyint_min 50.0 -force_key_frames expr:gte(t,n_forced*2) -b:v:1 1000k -maxrate 1000k -bufsize 40.0k -c:v:2 libx264 -preset veryfast -pix_fmt yuv420p -g 50.0 -keyint_min 50.0 -force_key_frames expr:gte(t,n_forced*2) -b:v:2 2000k -maxrate 2000k -bufsize 80.0k -c:v:3 libx264 -preset veryfast -pix_fmt yuv420p -g 50.0 -keyint_min 50.0 -force_key_frames expr:gte(t,n_forced*2) -b:v:3 4500k -maxrate 4500k -bufsize 180.0k -strict -2 -y -f mpegts -r 25 udp://239.0.0.1:1234?pkt_size=1316
ffmpeg ... -re -i - -f lavfi -i anullsrc=r=48000:cl=stereo
-filter_complex [0:v]drawtext=fontfile=/root/Vera.ttf:fontsize=12:text='eyevinntechnology/toolbox-loopts':fontcolor=white@0.9:x=20:y=20:shadowcolor=black:shadowx=2:shadowy=1,drawtext=fontfile=/root/Vera.ttf:fontsize=200:text='%{localtime\:%T}':fontcolor=white@0.9:x=(w-tw)/2:y=250:shadowcolor=black:shadowx=2:shadowy=1,drawtext=fontfile=/root/Vera.ttf:fontsize=40:text='[%{n}/%{pts}]':fontcolor=white@0.9:x=(w-tw)/2:y=h-th-10:shadowcolor=black:shadowx=2:shadowy=1[overlay]
[overlay]split=4[o1][o2][o3][o4]
[o1]scale=480:360,drawtext=fontfile=/root/Vera.ttf:fontsize=12:text='480x360':fontcolor=white@0.9:x=(w-tw)/2:y=20:shadowcolor=black:shadowx=2:shadowy=1[out360]
-map [out360] -map 1:0 -map [out480] -map [out720] -map [out1080]
-c:a aac -shortest
-c:v:0 libx264 -preset veryfast -pix_fmt yuv420p -g 50.0 -keyint_min 50.0 -force_key_frames expr:gte(t,n_forced*2) -b:v:0 400k -maxrate 400k -bufsize 16.0k -c:v:1 libx264 -preset veryfast -pix_fmt yuv420p -g 50.0 -keyint_min 50.0 -force_key_frames expr:gte(t,n_forced*2) -b:v:1 1000k -maxrate 1000k -bufsize 40.0k -c:v:2 libx264 -preset veryfast -pix_fmt yuv420p -g 50.0 -keyint_min 50.0 -force_key_frames expr:gte(t,n_forced*2) -b:v:2 2000k -maxrate 2000k -bufsize 80.0k -c:v:3 libx264 -preset veryfast -pix_fmt yuv420p -g 50.0 -keyint_min 50.0 -force_key_frames expr:gte(t,n_forced*2) -b:v:3 4500k -maxrate 4500k -bufsize 180.0k
-strict -2 -y -f mpegts -r 25  udp://host.docker.internal:9998?pkt_size=1316
docker run --rm -v $PWD:/mnt eyevinntechnology/toolbox-loopts --withtc --multibitrate Sunrise.mp4 "udp://239.0.0.1:1234?pkt_size=1316"

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store