Drawtext, drawbox or overlay on only a single frame using FFmpeg

喜欢而已 提交于 2019-12-10 13:57:45

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/7979585/drawtext-drawbox-or-overlay-on-only-a-single-frame-using-ffmpeg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!