FFmpeg -ss 奇怪的行为

发布于 2024-11-28 12:03:40 字数 325 浏览 0 评论 0原文

我一直在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

兔姬 2024-12-05 12:03:40

这是一个有根据的猜测。当-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.

扶醉桌前 2024-12-05 12:03:40

wberry的回答确实很有教养。阅读文档可以进一步提供帮助:

'-ss位置(输入/输出)'

当用作输入选项(在 -i 之前)时,在此输入文件中查找位置。当用作输出选项(在输出文件名之前)时,解码但丢弃输入,直到时间戳到达位置。这速度较慢,但​​更准确。

(位置可以以秒为单位,也可以采用 hh:mm:ss[.xxx] 形式。)

(参见 http://ffmpeg.org/ffmpeg.html#Main-options< /a>)


我目前正在编写一个音频采集应用程序,并且,因此,我正在使用较慢但更准确的方法。您可以选择最佳方法。

wberry's answer is indeed a very educated one. Reading the documentation can help even further:

‘-ss position (input/output)’

When used as an input option (before -i), seeks in this input file to position. When used as an output option (before an output filename), decodes but discards input until the timestamps reach position. This is slower, but more accurate.

(position may be either in seconds or in hh:mm:ss[.xxx] form.)

(as found in http://ffmpeg.org/ffmpeg.html#Main-options)

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.

血之狂魔 2024-12-05 12:03:40

我还刚刚完成了一个从视频内容生成缩略图的应用程序。

你应该检查一下这个
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 frame time 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.

心房敞 2024-12-05 12:03:40

当 -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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文