2

I am able to add text to a video on my hard disk, before I braodcast it...by using the command.

ffmpeg -y -i IMG_0696.MOV -acodec libmp3lame -vcodec msmpeg4 \
-b:a 192k -b:v 1000k -ar 44100 \
-vf "drawtext=text=string1 string2 string3 string4 string5 string6 string7 :expansion=normal:fontfile=/Windows/Fonts/cambriai.ttf: y=0:x=h-(2*lh)-n: fontcolor=white: fontsize=40: box=1: boxcolor=0x00000000@1" \
-an IMG_0696.avi

Now, I want to add different texts at various time instances. It should be read from a file which has the formatthe format : For example

00:00:10 : google
00:00:20 : yahoo
00:00:30 : msft
.
.
.
00:00:60 : amzn
.
.
.
00:05:30 : java

Is there a way to make ffmpeg read the file and add text at specified times? Eventually, I would like to add live ticker symbol to a video before broadcasting it.

1
  • Not sure if there is a way to do it "on the fly", but if you want to add text at various intervals you are better off using a subtitle like format such as .srt and muxing in directly to say an mkv container. Example: ffmpeg -i infile -i subtitle.srt -scodec copy -acodec copy -vcodec copy outfile.mkv. Look up srt format.
    – Rajib
    Oct 25, 2013 at 7:41

1 Answer 1

1

From the source code of the drawtext filter (from libavfilter/vf_drawtext.c in the source tree), there appears to be a textfile parameter which can specify a path to a file containing the string to draw (as opposed to setting the text parameter as in your example). You may want to experiment with passing it a filepath as textfile, and updating the file while viewing the video output.

You would also need another program/daemon running in parallel to update the file (which would just contain the current text to be displayed), but this program would be fairly trivial assuming you could synchronize it with the system clock.


Alternatively, you can modify the drawtext filter itself to display a particular string based on the current timecode (which is available to FFmpeg filters). While this would require modifying the filter's source code and recompiling from scratch, it would also avoid the use of a separate program/daemon running in parallel (as your own code would be invoked whenever FFmpeg tries to draw a string).

However, assuming the textfile parameter works (read: is updated every frame), that would probably be a better method, as a simple daemon to update the text file could be written in a scripting language like Python.

1
  • Thanks very much. I tried the option...but it pretty much behaves like text option. And the file seems to be read all at once (look at load_textfile() or line 401). If I don't get any better answers, I will try modifying ffmpeg and see if it works.
    – user763410
    Jun 10, 2013 at 0:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .