使用FFmpeg仅在单个框架上绘制文字,绘图框或叠加层 [英] Drawtext, drawbox or overlay on only a single frame using FFmpeg

查看:898
本文介绍了使用FFmpeg仅在单个框架上绘制文字,绘图框或叠加层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在FFmpeg上使用 drawtext 绘图框 avfilters,这是人类已知的两个最不了解的功能。

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

我正在努力解决如果我只能在单个框架上使用它们,即框架22上的绘图。

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

当前命令:

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

提到的两个元素 n t 。但是,我似乎只能在x和y中使用它们。

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.

任何帮助或FFmpeg指导都将非常感激。

Any help or FFmpeg guidance would be gratefully received.

推荐答案

在一个很好的例子中,FFmpeg总是保持你的脚趾,这对于 drawtext ,非常痛苦, drawbox

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

关键是 drawtext 包括 draw 参数:


绘制

设置一个表达式,该表达式指定是否应绘制文本。如果表达式求值为0,则不绘制文本。这对于指定只有在满足特定条件时才应绘制文本是有用的。

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.

所以只显示框架22上的文本:

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 没有 draw 参数,没有一般的方法来模拟它,所以你会做一些事情,像提取你想要放置的视频的一部分框,然后用偏移量覆盖:

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

(尽管这将使最后一帧 boxed.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.

这篇关于使用FFmpeg仅在单个框架上绘制文字,绘图框或叠加层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆