当我使用此命令时:
ffmpeg -i original.mp4 -codec:v:0 libx264 -b:v 650k -crf 21 -minrate:v 0k -maxrate:v 750k -bufsize:v 5000k -r 30 -preset slow -x264opts "no-scenecut" -vcodec libx264 -force_key_frames "expr:bitor(eq(t,0),gte(t,prev_forced_t+5))" -f mp4 test.mp4
我总是得到比这个命令更小的文件大小(相同的命令,但没有:-x264opts"no scenecut"):
ffmpeg -i original.mp4 -codec:v:0 libx264 -b:v 650k -crf 21 -minrate:v 0k -maxrate:v 750k -bufsize:v 5000k -r 30 -preset slow -vcodec libx264 -force_key_frames "expr:bitor(eq(t,0),gte(t,prev_forced_t+5))" -f mp4 test.mp4
我认为只有当使用I帧而不是p或B帧更有效时,场景才会使用I帧
在什么情况下我们需要使用场景切换功能?
当scenecut
触发时,如果距离大于min-keyint
,则会放入IDR,否则会放入I帧。
以下是doom9.org论坛上发布的一些伪代码(添加到此处以供将来参考):
encode current frame as (a really fast approximation of) a P-frame and an I-frame.
if ((distance from previous keyframe) > keyint) then
set IDR-frame
else if (1 - (bit size of P-frame) / (bit size of I-frame) < (scenecut / 100) * (distance from previous keyframe) / keyint) then
if ((distance from previous keyframe) >= minkeyint) then
set IDR-frame
else
set I-frame
else
set P-frame
encode frame for real.
当不需要固定的GOP/强制关键帧时,应该使用scenecut
。如果您试图为ABR传递进行编码,那么您也可以使用两次编码,并在pass-1上生成最高分辨率的stat文件,然后在pass-2上为每个格式副本重复使用它。