Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
919 views
in Technique[技术] by (71.8m points)

ffmpeg - Drawing dynamic text on video stream

I'm trying to change text dynamically every 5 minutes on my live video stream This is the argument im using:

-vf "drawtext=fontsize=40:fontfile=FreeSerif.ttf:text='hello world':x=(w-text_w)/2:y=(h-text_h)/2"

I tried 'c' in the FFMPEG console windows but I can't get it right, I always get a parse error. Is there an example of how to use this options?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Exept a reload you also need to write the file atomically. Update the text to a temporarily file first and then rename it. If not, at some point FFMpeg will read null data and fails when the file is created and no text is written yet.

  • Create livetext.txt.tmp with the text for the next 5 minutes.
  • Rename livetext.txt.tmp to livetext.txt.

repeat this process every 5 minutes.

-vf "drawtext=fontsize=40:fontfile=FreeSerif.ttf:textfile=/path/livetext.txt:x=(w-text_w)/2:y=(h-text_h)/2:reload=1"

With reload Ffmpeg reads the text every frame, so updates are almost instantaneous. For details see Drawtext filter


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...