FFMpeg:如何使用between()选择最后一秒? [英] FFMpeg: how to use between() to select last second?

查看:85
本文介绍了FFMpeg:如何使用between()选择最后一秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用可绘制文字的标题,该标题应在视频结束前一秒消失:

I'm trying to apply a caption using drawtext that should disappear one second before the video end:

ffmpeg -i input.mp4 -vf "drawtext=enable='between(t,0,5)':fontfile=font.ttf:text='Some caption':x=60:y=640:fontsize=40:fontcolor=#f0f0f0@0.9" -vcodec libx264 -crf 27 -preset ultrafast -strict -2 -acodec copy output.mp4

问题是我事先不知道视频长度.我试过使用'between(t,0,-1)',但是它不起作用,标题从不显示.有人知道有没有办法不必先打开视频来检查长度,而仅在绘制字幕之后才可以这样做?预先感谢!

The problem is that I don't know the video length beforehand. I've tried using 'between(t,0,-1)' but it doesn't work, the caption never shows up. Anyone knows if is there a way to do this without having to open the video first to check length and only after that draw the caption? Thanks in advance!

推荐答案

FFmpeg不会将流持续时间传达给过滤器,因此必须以回旋方式完成.

FFmpeg does not convey the stream duration to filters, so this has to be done in a roundabout manner.

FFmpeg具有sseof函数,可以从文件末尾查找.它还有一个copyts选项来维护时间戳.因此,我们将输入加载两次,一次是完整输入,另一次是最后一秒.然后,我们在整个第一个输入上绘制文本,但在第二个输入上覆盖最后一个第二个文本,由于保留了时间戳,该文本将被适当地刻录.

FFmpeg has a sseof function that can seek from the end of a file. It also has a copyts option to maintain timestamps. So, we load the input twice, once the full input, and the other, just the last second. Then we draw the text on the entire 1st input but overlay the last second from the 2nd input, which because of the retained timestamps, will be burnt in place.

ffmpeg -copyts -i input.mp4 -sseof -1 -i input.mp4 -filter_complex  "[0]drawtext=fontfile=font.ttf:text='Some caption':x=60:y=640:fontsize=40:fontcolor=#f0f0f0@0.9[txt];[txt][1]overlay" -vcodec libx264 -crf 27 -preset ultrafast -acodec copy output.mp4

这篇关于FFMpeg:如何使用between()选择最后一秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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