5

I'm using the drawtext and drawbox avfilters on FFmpeg, two of the most poorly documented functions known to man.

I'm struggling to work out if and how I can use them on only a single frame, i.e., drawtext on frame 22.

Current command:

ffmpeg -i test.wmv -y -b 800k -f flv -vcodec libx264 -vpre default -s 768x432 \
  -g 250 -vf drawtext="fontfile=/home/Cyberbit.ttf:fontsize=24:text=testical:\
  fontcolor=green:x=100:y=200" -qscale 8 -acodec libfaac -sn -vstats out.flv

Two elements mentioned in the documentation are n and t. However, I only seem to be able to use them in x and y. Not in text or even as other parameters.

Any help or FFmpeg guidance would be gratefully received.

blahdiblah
  • 30,909
  • 18
  • 92
  • 149
waxical
  • 3,616
  • 7
  • 40
  • 66
  • 1
    possible duplicate of [ffmpeg drawbox on a given frame](http://stackoverflow.com/questions/17339841/ffmpeg-drawbox-on-a-given-frame) – Jannes Feb 25 '15 at 12:05

1 Answers1

3

In a great example of FFmpeg always keeping you on your toes, this is trivial to do with drawtext and extremely painful with drawbox.

The key is that drawtext includes the draw parameter:

draw
Set an expression which specifies if the text should be drawn. If the expression evaluates to 0, the text is not drawn. This is useful for specifying that the text should be drawn only when specific conditions are met.

So to only show text on frame 22:

ffmpeg -i in.wmv -vf drawtext="fontfile=font.ttf:text='blah':draw='eq(n,22)'" out.flv

drawbox has no draw parameter, and there's no general way to emulate it, so you're left doing something like extracting the portion of video that you want to put the box on and then overlaying it with an offset:

ffmpeg -i in.wmv -t 1 -ss 10 -vf drawbox=10:10:20:20:red boxed.flv
ffmpeg -i in.wmv -itsoffset 10 -i boxed.flv -filter_complex overlay out.flv

(though this will leave the last frame of boxed.flv visible forever) or breaking up the video into multiple pieces, drawing on the proper pieces, and then recombining.

blahdiblah
  • 30,909
  • 18
  • 92
  • 149
  • 3
    drawbox (and drawtext) have Video Editing capabilities these days that allow you to do the same thing in a generic way. http://stackoverflow.com/questions/17339841/ffmpeg-drawbox-on-a-given-frame – Jannes Feb 25 '15 at 12:04