ffmpeg 在一个命令中剪切视频和刻录字幕 [英] ffmpeg cut video and burn subtitle in a single command

查看:54
本文介绍了ffmpeg 在一个命令中剪切视频和刻录字幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从视频中剪下一段并在其中刻录字幕.

I want to cut a piece out of a video and burn subtitle in that piece.

我可以通过 3 个步骤完成此操作:

I can do this in 3 steps:

  1. 剪切视频
    ffmpeg -ss 25:00 -to 26:00 -i vid.mp4 -c copy out.mp4

剪下副标题
ffmpeg -i sub.srt -ss 25:00 -to 26:00 out.srt

在视频片段中刻录字幕
ffmpeg -i out.mp4 -vf captions=out.srt -c:a copy -y final.mp4

但我想在单个 ffmpeg 命令中执行此操作.

But I want to do this in a single ffmpeg command.

如果我这样做
ffmpeg -ss 25:00 -to 26:00 -i vid.mp4 -vf captions=sub.srt -c:a copy -y final.mp4
视频被剪切,但没有刻录字幕.
这很快.

If I do this
ffmpeg -ss 25:00 -to 26:00 -i vid.mp4 -vf subtitles=sub.srt -c:a copy -y final.mp4
the video is cut but no subtitle is burned into it.
This is fast.

如果我这样做
ffmpeg -i vid.mp4 -ss 25:00 -to 26:00 -vf captions=sub.srt -c:a copy -y final.mp4
视频已剪切,字幕正确刻录,但开始写入 final.mp4 时出现延迟.
我认为 ffmpeg 从一开始就处理 vid.mp4 直到达到 -ss 时间(并删除那部分)然后继续处理写入final.mp4

If I do this
ffmpeg -i vid.mp4 -ss 25:00 -to 26:00 -vf subtitles=sub.srt -c:a copy -y final.mp4
the video is cut and subtitles burned correctly,but there is a delay in starting writing the final.mp4.
I think ffmpeg is processing vid.mp4 from the beginning till it reach the -ss time (and drop that part) then continue processing and writing it to final.mp4

有没有办法在单个 ffmpeg 命令中快速完成此操作?
就像 ffmpeg 直接进入 -ss 时间并剪切,处理它,在其中刻录字幕.

Is there a way to do this fast and in a single ffmpeg command?
Like ffmpeg going directly to -ss time and cut that, process it, burn subtitle in it.

谢谢

推荐答案

是的,字幕过滤器在内部打开字幕文件并且不知道视频的搜索点,因为 ffmpeg 在搜索后重置时间戳.

Yes, the subtitles filter opens the subtitle file internally and isn't aware of the seek point for the video since ffmpeg resets timestamps after seeking.

所以保留源时间戳,然后重置它们,即

So preserve the source timestamps and then reset them i.e.

ffmpeg -ss 25:00 -to 26:00 -copyts -i vid.mp4 -vf subtitles=sub.srt  -c:a copy -ss 25:00 -y final.mp4

这篇关于ffmpeg 在一个命令中剪切视频和刻录字幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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