ffmpeg:如果超出阈值,则降低fps,但如果低于阈值,则不提高 [英] ffmpeg: reduce fps if over threshold but do not increase if under threshold

查看:246
本文介绍了ffmpeg:如果超出阈值,则降低fps,但如果低于阈值,则不提高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ffmpeg CLI允许您指定-r <fps>-vf fps=<fps>为输出设置固定的FPS.

The ffmpeg CLI allows your to specify -r <fps> or -vf fps=<fps> to set a fixed FPS for your output.

我想要得到的行为是:

  • 输入可以具有任意FPS(可能为20-120).
  • 如果输入FPS大于30,则将其降低到30 FPS.
  • 如果输入的FPS为< = 30,请不要修改FPS.

更多内容:

上述选项非常适合将视频标准化为固定的FPS,但不能很好地确保视频不会有效地超过某个FPS阈值.确实,如果我将-r 30设置为29 fps,那么在我的用例不需要ffmpeg的情况下,ffmpeg会将其提高到30的CPU数量.

Aforementioned options are great to normalize videos to a fixed FPS but not so good to make sure videos do not get over a certain FPS threshold efficiently. Indeed, if I set -r 30 and the video is 29 fps, ffmpeg is going to us a lot of CPU to raise it to 30 when it wasn't needed for my use-case.

推荐答案

这可以在恒定帧频视频上完成-我的以下方法可能适用于VFR视频,但是我没有合适的视频可以测试.

This can be done on constant frame rate video - my method below may work on VFR video, but I don't have a suitable video to test.

基本命令:

ffmpeg -i 120.mp4 -vf "select='eq(n,0)+if(gt(t-prev_selected_t,1/30.01),1,0)'" -vsync 0 out.mp4

在120 fps的流上,

On a 120 fps stream,

Video: h264 (High) ... 120 fps, 120 tbr, 15360 tbn, 240 tbc

这产生

Video: h264 (High) ... 30.08 fps, 30 tbr, 15360 tbn, 240 tbc

在选择第一帧后,选择过滤器的作用是仅选择其他帧,如果它们与先前选择的帧之间的间隔为1/30秒或更大.实际上,这会将视频的速度降低到30 fps以下.

What the select filter does, after selecting the first frame, is only select further frames if their interval from the previously selected frame is 1/30th of a second or more. In practice, this decimates videos to below 30 fps.

需要注意的两件事:

1)最后一帧的持续时间被截断,因此fps值将略大于目标值.但是其他所有帧都以30 fps的速度循环.

1) the duration of the last frame is truncated, so the fps value will be slightly greater than the target. But all other frames cycle at 30 fps.

2)输出帧速率是通过将源速率除以整数而获得的最高数字.因此,如果在命令中将30.01替换为26,则结果将是24 tbr,因为将120除以整数既不能得到25也不能得到26.这样做的好处是避免了输出中的运动停顿.命令中的除数应略大于上限,即30.01而不是30.否则,结果令人不安.

2) The output framerate is the highest number obtained by dividing the source rate by an integer. So, if in the command, 30.01 is replaced by 26, the result will be 24 tbr since neither 25 nor 26 can be obtained by dividing 120 by an integer. This has the benefit of avoiding motion stutter in the output. The divisor in the command should be slightly greater than the ceiling i.e. 30.01 instead of 30. Else, the results are wobbly.

如果输入速度为30 fps或更低,则将选择所有帧.

If the input is 30 fps or less, then all frames are selected.

附录:

如果上述命令的输出通过管道传递到另一个ffmpeg实例,则输出fps是准确的,编解码器速率tbc也将重置.

If the output of the above command is piped to another ffmpeg instance, the output fps is exact and the codec rate tbc is reset as well.

ffmpeg -i 120.mp4 -vf "select='eq(n,0)+if(gt(t-prev_selected_t,1/30.01),1,0)'" -vsync 0
        -c:v rawvideo -c:a pcm_s16le -f nut - | ffmpeg -f nut -i - out.mp4

这篇关于ffmpeg:如果超出阈值,则降低fps,但如果低于阈值,则不提高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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