How to disable B frames in FFmpeg for H.264 encoding?

3.7k Views Asked by At

I'm encoding video with h264_nvenc, and I would like to disable B-Frames. I'm trying to use -bframes 0 parameter, but I'm not sure if it works, and where exactly put the command. For now, this is my code:

-probesize 10MB -s 1920x1080 -framerate 30 -i video.h264 -c:v h264_nvenc -preset p7 -tune 4 -rc:v vbr -cq:v 1 -profile:v high -pix_fmt yuv420p -s 1920x1080 -r:v 30 video.h264

Furthermore, should I need to use bframes 0 when I'm already using tune 4 (lossless)?

The original video doesn't have any B-frame.

1

There are 1 best solutions below

0
aergistal On BEST ANSWER

The FFmpeg option is:

bf integer (encoding,video) Set max number of B frames between non-B-frames.

Must be an integer between -1 and 16. 0 means that B-frames are disabled. If a > value of -1 is used, it will choose an automatic value depending on the encoder.

Default value is 0.

In libavcodec/nvenc.c it sets frameIntervalP (0 - intra-only, 1 - IPP, 2 - IBP, 3 - IBBP etc.):

if (avctx->gop_size > 0) {
    if (avctx->max_b_frames >= 0) {
        /* 0 is intra-only, 1 is I/P only, 2 is one B-Frame, 3 two B-frames, and so on. */
        ctx->encode_config.frameIntervalP = avctx->max_b_frames + 1;
    }

    ctx->encode_config.gopLength = avctx->gop_size;
} else if (avctx->gop_size == 0) {
    ctx->encode_config.frameIntervalP = 0;
    ctx->encode_config.gopLength = 1;
}

For the older LosslessHP preset the frameIntervalP is 1 (IPP).

If you use the new presets as recommended you should set it manually. See the NVENC Preset Migration Guide.