FFmpeg Drawtext Load Text From File Dynamically

Overlaying dynamic text onto videos is a common requirement for live streams, automated video generation, and real-time monitoring displays. This guide explains how to use the FFmpeg drawtext video filter to load text from an external file and automatically update the video overlay in real-time as the file’s content changes.

The Core FFmpeg Command

To load text from an external file dynamically, you must use the textfile parameter to specify the file path, and set the reload parameter to 1.

Here is the basic command structure:

ffmpeg -i input.mp4 -vf "drawtext=fontfile=Arial.ttf:textfile=status.txt:reload=1:fontcolor=white:fontsize=24:x=50:y=50" -codec:a copy output.mp4

Parameter Breakdown

Real-Time Updates During Live Streams

If you are running a live stream or generating an infinite loop video, you can dynamically update the contents of your text file from an external script (such as Python, Bash, or Node.js).

For example, you can write a script that updates status.txt with the current time, weather data, or system performance metrics:

echo "Current CPU Temp: 45C" > status.txt

FFmpeg will detect the change on the next frame refresh and display the updated string without interrupting the video stream.

Handling File Access Conflicts

When writing to the text file while FFmpeg is reading it, you might occasionally get a blank frame if FFmpeg reads the file mid-write. To prevent this, write the new content to a temporary file first, and then perform an atomic replace (rename) operation:

echo "New Dynamic Text" > status.tmp && mv status.tmp status.txt