FFmpeg -ss 奇怪的行为
我一直在使用 FFmpeg 将单帧提取到图像中。尽管进行了一些谷歌搜索,结果发现运行:
ffmpeg.exe -i video.avi -ss 00:30:00 -y -an -vframes 1 test.png
... 运行速度比以下命令慢得多,这几乎相同,但是是瞬时的:
ffmpeg.exe -ss 00:30:00 -i video.avi -y -an -vframes 1 test.png
唯一的区别是 -i 和 -ss 的顺序。这是故意的“功能”吗?这里的差异是否有某种技术原因?
I've been using FFmpeg to extract single frames into an image. Though some Googling, it turns out that running:
ffmpeg.exe -i video.avi -ss 00:30:00 -y -an -vframes 1 test.png
...runs SIGNIFICANTLY slower than the following, which is nearly identical, but instantaneous:
ffmpeg.exe -ss 00:30:00 -i video.avi -y -an -vframes 1 test.png
The only difference is the order of -i and -ss. Is this an intentional 'feature'? Is there some sort of technical reason for the difference here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是一个有根据的猜测。当
-ss
出现在-i
之前时,它被视为输入指令,因此视频流的第一帧是30秒处的帧。当-ss
出现在-i
之后时,它被视为效果,并且前30秒的帧被读取并丢弃,导致性能差异。This is an educated guess. When
-ss
occurs before-i
, it is treated as instructions for the input, so the first frame of the video stream is the one at 30 seconds. When-ss
occurs after-i
, it is treated as an effect, and the first 30 seconds of frames are read and dropped, leading to a performance difference.wberry的回答确实很有教养。阅读文档可以进一步提供帮助:
我目前正在编写一个音频采集应用程序,并且,因此,我正在使用较慢但更准确的方法。您可以选择最佳方法。
wberry's answer is indeed a very educated one. Reading the documentation can help even further:
I'm currently writing an audio grabber application, and, as such, I'm using the slower but more accurate method. It is up to you to choose the best approach.
我还刚刚完成了一个从视频内容生成缩略图的应用程序。
你应该检查一下这个
http://ffmpeg.org/trac/ffmpeg/wiki/Seeking%20with%20FFmpeg
它描述了一种将
-ss
标志(来自两个位置)组合成一个统一命令的方法,该命令提供帧时间
精度,并具有更快的帧选择。ffmpeg -ss 00:02:30 -i Underworld.Awakening.avi -ss 00:00:30 -vframes 1 out3.jpg
还包含其他可能技巧的链接,例如单个拇指的多个拇指视频。
I have also just finished an app that generates thumbnails from video content.
You should check this out,
http://ffmpeg.org/trac/ffmpeg/wiki/Seeking%20with%20FFmpeg
It describes a method of combining the
-ss
flag (from both locations) into a unified command that provides frametime
accuracy, with a quicker frame selection.ffmpeg -ss 00:02:30 -i Underworld.Awakening.avi -ss 00:00:30 -vframes 1 out3.jpg
and also includes links to other possible tricks, like multiple thumbs from a single video.
当 -ss 出现在 -i 之前时,它会转到最近的关键帧(在 25 fps 的 H.264 文件中每 10 秒一次,因为 H.264 将使用 250 的 GOP)。这使得查找速度非常快,因此您可以在 -i 之后添加另一个 -ss 以转到第一个 -ss 之后的小数位置。
在 -i 之后加上 -ss 将寻找确切的位置,但速度非常慢。
有关示例和更多信息,请参阅 https://trac.ffmpeg.org/wiki/Seeking
When -ss occurs before the -i, it goes to the closest key frame (which is every 10 seconds in H.264 files for 25 fps, since H.264 will use a GOP of 250). This makes seeking really fast, so you can add another -ss after the -i to go to a fractional location after the first -ss.
Having -ss after -i will seek to the exact location, but it is very slow.
See https://trac.ffmpeg.org/wiki/Seeking for examples and more information