| @@ -370,6 +370,22 @@ static int nvenc_check_capabilities(AVCodecContext *avctx) | |||||
| return AVERROR(ENOSYS); | return AVERROR(ENOSYS); | ||||
| } | } | ||||
| #ifdef NVENC_HAVE_BFRAME_REF_MODE | |||||
| ret = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_BFRAME_REF_MODE); | |||||
| if (ctx->b_ref_mode == NV_ENC_BFRAME_REF_MODE_EACH && ret != 1) { | |||||
| av_log(avctx, AV_LOG_VERBOSE, "Each B frame as reference is not supported\n"); | |||||
| return AVERROR(ENOSYS); | |||||
| } else if (ctx->b_ref_mode != NV_ENC_BFRAME_REF_MODE_DISABLED && ret == 0) { | |||||
| av_log(avctx, AV_LOG_VERBOSE, "B frames as references are not supported\n"); | |||||
| return AVERROR(ENOSYS); | |||||
| } | |||||
| #else | |||||
| if (ctx->b_ref_mode != 0) { | |||||
| av_log(avctx, AV_LOG_VERBOSE, "B frames as references need SDK 8.1 at build time\n"); | |||||
| return AVERROR(ENOSYS); | |||||
| } | |||||
| #endif | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| @@ -988,6 +1004,10 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx) | |||||
| if (ctx->coder >= 0) | if (ctx->coder >= 0) | ||||
| h264->entropyCodingMode = ctx->coder; | h264->entropyCodingMode = ctx->coder; | ||||
| #ifdef NVENC_HAVE_BFRAME_REF_MODE | |||||
| h264->useBFramesAsRef = ctx->b_ref_mode; | |||||
| #endif | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| @@ -40,6 +40,12 @@ typedef void ID3D11Device; | |||||
| #define RC_MODE_DEPRECATED 0x800000 | #define RC_MODE_DEPRECATED 0x800000 | ||||
| #define RCD(rc_mode) ((rc_mode) | RC_MODE_DEPRECATED) | #define RCD(rc_mode) ((rc_mode) | RC_MODE_DEPRECATED) | ||||
| // SDK 8.1 compile time feature checks | |||||
| #if NVENCAPI_VERSION >= 0x01000008 | |||||
| #define NVENC_HAVE_BFRAME_REF_MODE | |||||
| #define NVENC_HAVE_QP_MAP_MODE | |||||
| #endif | |||||
| typedef struct NvencSurface | typedef struct NvencSurface | ||||
| { | { | ||||
| NV_ENC_INPUT_PTR input_surface; | NV_ENC_INPUT_PTR input_surface; | ||||
| @@ -174,6 +180,7 @@ typedef struct NvencContext | |||||
| int cqp; | int cqp; | ||||
| int weighted_pred; | int weighted_pred; | ||||
| int coder; | int coder; | ||||
| int b_ref_mode; | |||||
| } NvencContext; | } NvencContext; | ||||
| int ff_nvenc_encode_init(AVCodecContext *avctx); | int ff_nvenc_encode_init(AVCodecContext *avctx); | ||||
| @@ -126,6 +126,17 @@ static const AVOption options[] = { | |||||
| { "cavlc", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_H264_ENTROPY_CODING_MODE_CAVLC }, 0, 0, VE, "coder" }, | { "cavlc", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_H264_ENTROPY_CODING_MODE_CAVLC }, 0, 0, VE, "coder" }, | ||||
| { "ac", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_H264_ENTROPY_CODING_MODE_CABAC }, 0, 0, VE, "coder" }, | { "ac", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_H264_ENTROPY_CODING_MODE_CABAC }, 0, 0, VE, "coder" }, | ||||
| { "vlc", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_H264_ENTROPY_CODING_MODE_CAVLC }, 0, 0, VE, "coder" }, | { "vlc", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_H264_ENTROPY_CODING_MODE_CAVLC }, 0, 0, VE, "coder" }, | ||||
| #ifdef NVENC_HAVE_BFRAME_REF_MODE | |||||
| { "b_ref_mode", "Use B frames as references", OFFSET(b_ref_mode), AV_OPT_TYPE_INT, { .i64 = NV_ENC_BFRAME_REF_MODE_DISABLED }, NV_ENC_BFRAME_REF_MODE_DISABLED, NV_ENC_BFRAME_REF_MODE_MIDDLE, VE, "b_ref_mode" }, | |||||
| { "disabled", "B frames will not be used for reference", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_BFRAME_REF_MODE_DISABLED }, 0, 0, VE, "b_ref_mode" }, | |||||
| { "each", "Each B frame will be used for reference", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_BFRAME_REF_MODE_EACH }, 0, 0, VE, "b_ref_mode" }, | |||||
| { "middle", "Only (number of B frames)/2 will be used for reference", 0,AV_OPT_TYPE_CONST, { .i64 = NV_ENC_BFRAME_REF_MODE_MIDDLE }, 0, 0, VE, "b_ref_mode" }, | |||||
| #else | |||||
| { "b_ref_mode", "(not supported)", OFFSET(b_ref_mode), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE, "b_ref_mode" }, | |||||
| { "disabled", "", 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, VE, "b_ref_mode" }, | |||||
| { "each", "", 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, VE, "b_ref_mode" }, | |||||
| { "middle", "", 0, AV_OPT_TYPE_CONST, { .i64 = 2 }, 0, 0, VE, "b_ref_mode" }, | |||||
| #endif | |||||
| { NULL } | { NULL } | ||||
| }; | }; | ||||