[FFmpeg-user] drawtext reload=N > 1?

Steven Kan steven at kan.org
Mon Feb 28 07:07:47 EET 2022


I am overlaying real-time weather on streaming video:

https://www.youtube.com/channel/UCIVY11504PcY2sy2qpRhiMg/live

I have a script reading from openweather.org every 10 minutes and writing to weather.txt*, and then drawtext reads weather.txt and applies it via:

./ffmpeg -thread_queue_size 2048 -hwaccel videotoolbox -i 'rtsp://anonymous:password1@192.168.1.13:554' -hwaccel videotoolbox -i 'rtsp://anonymous:password1@192.168.1.45:554' -vcodec h264_videotoolbox -b:v 5000k -acodec copy -t 2:00:00 -filter_complex "hstack=inputs=2,fps=20[stacked];[stacked]drawtext='fontfile=/System/Library/Fonts/Helvetica.ttc: textfile=/tmp/weather.txt: fontcolor=white: fontsize=48: x=(w-text_w)*0.01: y=(h-text_h)*0.01:reload=600'" -f flv "rtmp://a.rtmp.youtube.com/live2/<my-youtube-streaming-key>”

It’s working, but it seems very inefficient to read weather.txt every 1 frame when it gets updated only every 12,000 frames.

According to the documentation, reload is a Boolean to read every frame or not, and attempting reload=2 or reload=600 results in:

[drawtext @ 0x7fa696010600] Unable to parse option value "2" as boolean

Would it be worthy feature request to allow drawtext to accept integer values N > 1, and then reload the text file every Nth frame? It seems like a win for CPU and I/O loading, with the benefit of being fully backward compatible with existing scripts that read in every 1 frame (e.g. reload=1).

Or are there downsides to this that I’m not seeing?

* and yes, I’m writing to weather.tmp and cping to weather.txt to prevent a file I/O collision.


More information about the ffmpeg-user mailing list