Skip to content
Advertisement

Can you insert text from a file in real time with ffmpeg streaming?

I have this code i use to stream a file and place the name of the show of the video at a certain time of the video ( name_of_show ) at the top of the screen, and the bottom of the screen it take the name of the show from video_title.txt and places it on the bottom of the screen.

What I want to do is find a way at a interval say 1 or 2 minutes, pull whatever text is currently in video_title.txt and place it in the video for a few seconds.

I would update video_title.txt from another python program. Here’s my current code below.

JavaScript

Ultimately the effect I am trying to achieve is a long stream of lets say 1 hour on twitch/youtube where someone could send a text message and it would appear in the stream.

Advertisement

Answer

Use the reload=1 and textfile options in drawtext. From the drawtext filter documentation:

reload
If set to 1, the textfile will be reloaded before each frame. Be sure to update it atomically, or it may be read partially, or even fail.

textfile
A text file containing text to be drawn. The text must be a sequence of UTF-8 encoded characters.
This parameter is mandatory if no text string is specified with the parameter text.
If both text and textfile are specified, an error occurs.

Example:

JavaScript

To update atomically you can use mv or equivalent:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement