FFmpeg Drawtext Read Text from File Dynamically

Overlaying dynamic text onto videos is a crucial task for live streaming, automated video rendering, and displaying real-time data. This article explains how to use the FFmpeg drawtext filter to read text from an external file and update it dynamically on screen. You will learn the exact command-line syntax, key parameters like the reload option, and how to structure your files for seamless integration.

The Basic Command Syntax

To read text from an external file instead of hardcoding it into the FFmpeg command, you must use the textfile parameter inside the drawtext video filter.

Here is the fundamental command to achieve this:

ffmpeg -i input.mp4 -vf "drawtext=fontfile=/path/to/font.ttf:textfile='content.txt':reload=1:fontcolor=white:fontsize=24:x=(w-text_w)/2:y=h-50" -codec:a copy output.mp4

Parameter Breakdown

Practical Implementation Tips

Real-Time Updates with FFplay

If you want to test the dynamic updates in real-time on your screen before rendering a file, use ffplay:

ffplay -i input.mp4 -vf "drawtext=fontfile=arial.ttf:textfile='content.txt':reload=1:fontcolor=yellow:fontsize=32:x=10:y=10"

While the video is playing, open content.txt in a text editor, change the text, and save the file. The text overlay on the video screen will update instantly.

Automated Scripting

For live streams or dynamic dashboards, you can use an external Python, Bash, or Node.js script to write new data to content.txt (such as current time, song titles, or sensor data). FFmpeg will automatically grab the new content frame-by-frame as long as reload=1 is active.