1

I am using ffmpeg to encode raw pixels data (bgr32) into a video file.

Pixels data is being sent from java application to ffmpeg stdin pipe.

I am looking for a way to add a timestamp overlay to each frame in the encoded video file.

It looks like there is a way to add a timestamp of current time.

The instructions could be found here: http://einar.slaskete.net/2011/09/05/adding-time-stamp-overlay-to-video-stream-using-ffmpeg/

Examples of code from that site are this:

ffmpeg -f video4linux2 -i /dev/video0 -s 640x480 -r 30 -vf \
"drawtext=fontfile=/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf: \
text='\%T': [email protected]: x=7: y=460" -vcodec libx264 -vb 2000k \
-preset ultrafast -f mp4 output.mp4

And this:

ffmpeg -f video4linux2 -input_format mjpeg -s 1280x720 -i /dev/video0 \
-vf "drawtext=fontfile=/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf: \
text='%{localtime\:%T}': [email protected]: x=7: y=700" -vcodec libx264 \
-preset veryfast -f mp4 -pix_fmt yuv420p -y output.mp4

Video files that I am encoding were captured few days ago and I need to add a custom time to each frame. For example 12/12/2013 11:11:45 and not the current time.

Is it possible to do something like it using ffmpeg?

1 Answer 1

0

There is a drawtext filter when compiled with the --enable-libfreetype configuration. If you don't have this, you have to compile ffmpeg yourself – not terribly complicated though.

The easiest syntax would be:

ffmpeg -i <input> -vf 'drawtext=fontsize=15:fontfile=FreeSerif.ttf:text=LONG_LINE:y=100:x=100' output.mp4

This positions the text at 100 pixels offset from the top left corner. You can then use the enable option to specify a text for a certain frame, e.g. to show a text only for frame 123, you'd use:

drawtext=enable='eq(n,123)':fontsize=15:fontfile=FreeSerif.ttf:text='I':y=100:x=100

So, of course you have to procedurally generate the command to show a certain string for only a certain time.


Another idea would be to burn subtitles into the video from a pre-generated subtitle file.

2
  • Burning subtitles is an interesting ides. Thanks. It looks that there are no other options to pass text information for each frame using pipe or pregenerated file.
    – Marco
    Commented Jan 20, 2014 at 16:26
  • You can use -filter_complex_script to supply the path to a script containing filter options, but that's all I can think of.
    – slhck
    Commented Jan 20, 2014 at 18:11

You must log in to answer this question.

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