[FFmpeg-user] displaying real time text on output

DopeLabs dopelabs at dubstep.fm
Mon Aug 7 00:43:53 EEST 2017


you can use the drawtext filter.

i have several drawtext filters i run, displaying audio track titles, site name, original air date (or 'LIVE' if live).

the trick to having the text update mid stream or mid encode is to specify textfile="/path/file.txt":reload=1

reload=1 will cause ffmpeg to check the file every frame. 

you need to update the file atomically or ffmpeg may partially read the file, or even fail.

you can achieve this by not editing the file with an editor or even using echo "text" > file.txt... 

but instead save a new temp file, then mv tempfile.txt file.txt

here is an example of one that i use:

______

"drawtext=fontfile=/path/font.ttf:fontsize=28:fix_bounds=true:fontcolor=gray:alpha=.5:textfile=/path/file.txt:reload=1:y=(h-text_h)-5:x=(w-text_w)/2"
______


this creates semi transparent gray text at the top center of the frame, will auto scale if the amount of text exceeds the width of the frame so text wont get truncated.

if you are using this in a livestream scenario, you can see the text updates in real time.



i have not tried this when the input or output are not live streams... 

i would suspect it would be kind of hard to get the timing right since the input/output can be read/written faster than real time.  


on a side note:
im currently trying to figure out if its possible to use text expansion to pull metadata values from within the stream, and use in drawtext output. 

an example would be an mp3 audio live stream such as icecast or shoutcast, when song titles change in the stream, to display that value in drawtext output which updates mid-stream.

it looks like it could be done but im just struggling a bit trying to figure out the correct syntax, metadata keys, etc. 

so if anyone has any insight on that. im all ears.

-DL

> On Aug 6, 2017, at 11:39 43AM, tasos <tasoss at trigonongroup.com> wrote:
> 
> Hello.
> I know that this may be a stupid question but is it possible while encoding to apply a filter that displays text for example?
> I mean ffmpeg is already running and produces output.
> I don't want to take that output and apply the text filter there.I want to apply it on the already
> running ffmpeg process.
> Thanks!
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
> 
> To unsubscribe, visit link above, or email
> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".



More information about the ffmpeg-user mailing list