#include "internal.h"
#define NVENC_CAP 0x30
-#define IS_CBR(rc) (rc == NV_ENC_PARAMS_RC_CBR || \
- rc == NV_ENC_PARAMS_RC_2_PASS_QUALITY || \
- rc == NV_ENC_PARAMS_RC_2_PASS_FRAMESIZE_CAP)
+#define IS_CBR(rc) (rc == NV_ENC_PARAMS_RC_CBR || \
+ rc == NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ || \
+ rc == NV_ENC_PARAMS_RC_CBR_HQ)
const enum AVPixelFormat ff_nvenc_pix_fmts[] = {
AV_PIX_FMT_YUV420P,
return AVERROR(ENOSYS);
}
+ ret = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_WEIGHTED_PREDICTION);
+ if (ctx->weighted_pred > 0 && ret <= 0) {
+ av_log (avctx, AV_LOG_VERBOSE, "Weighted Prediction not supported\n");
+ return AVERROR(ENOSYS);
+ }
+
return 0;
}
return;
}
/* fall through */
- case NV_ENC_PARAMS_RC_2_PASS_VBR:
+ case NV_ENC_PARAMS_RC_VBR_HQ:
case NV_ENC_PARAMS_RC_VBR:
set_vbr(avctx);
break;
case NV_ENC_PARAMS_RC_CBR:
- case NV_ENC_PARAMS_RC_2_PASS_QUALITY:
- case NV_ENC_PARAMS_RC_2_PASS_FRAMESIZE_CAP:
+ case NV_ENC_PARAMS_RC_CBR_HQ:
+ case NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ:
break;
}
if (ctx->cbr) {
if (ctx->twopass) {
- ctx->rc = NV_ENC_PARAMS_RC_2_PASS_QUALITY;
+ ctx->rc = NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ;
} else {
ctx->rc = NV_ENC_PARAMS_RC_CBR;
}
} else if (ctx->cqp >= 0) {
ctx->rc = NV_ENC_PARAMS_RC_CONSTQP;
} else if (ctx->twopass) {
- ctx->rc = NV_ENC_PARAMS_RC_2_PASS_VBR;
+ ctx->rc = NV_ENC_PARAMS_RC_VBR_HQ;
} else if (avctx->qmin >= 0 && avctx->qmax >= 0) {
ctx->rc = NV_ENC_PARAMS_RC_VBR_MINQP;
}
}
+ if (ctx->rc >= 0 && ctx->rc & RC_MODE_DEPRECATED) {
+ av_log(avctx, AV_LOG_WARNING, "Specified rc mode is deprecated.\n");
+ av_log(avctx, AV_LOG_WARNING, "\tll_2pass_quality -> cbr_ld_hq\n");
+ av_log(avctx, AV_LOG_WARNING, "\tll_2pass_size -> cbr_hq\n");
+ av_log(avctx, AV_LOG_WARNING, "\tvbr_2pass -> vbr_hq\n");
+ av_log(avctx, AV_LOG_WARNING, "\tvbr_minqp -> (no replacement)\n");
+
+ ctx->rc &= ~RC_MODE_DEPRECATED;
+ }
+
if (ctx->flags & NVENC_LOSSLESS) {
set_lossless(avctx);
} else if (ctx->rc >= 0) {
ctx->encode_config.rcParams.zeroReorderDelay = 1;
if (ctx->quality)
- ctx->encode_config.rcParams.targetQuality = ctx->quality;
+ {
+ //convert from float to fixed point 8.8
+ int tmp_quality = (int)(ctx->quality * 256.0f);
+ ctx->encode_config.rcParams.targetQuality = (uint8_t)(tmp_quality >> 8);
+ ctx->encode_config.rcParams.targetQualityLSB = (uint8_t)(tmp_quality & 0xff);
+ }
}
static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)
h264->outputPictureTimingSEI = 1;
}
- if (cc->rcParams.rateControlMode == NV_ENC_PARAMS_RC_2_PASS_QUALITY ||
- cc->rcParams.rateControlMode == NV_ENC_PARAMS_RC_2_PASS_FRAMESIZE_CAP ||
- cc->rcParams.rateControlMode == NV_ENC_PARAMS_RC_2_PASS_VBR) {
+ if (cc->rcParams.rateControlMode == NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ ||
+ cc->rcParams.rateControlMode == NV_ENC_PARAMS_RC_CBR_HQ ||
+ cc->rcParams.rateControlMode == NV_ENC_PARAMS_RC_VBR_HQ) {
h264->adaptiveTransformMode = NV_ENC_H264_ADAPTIVE_TRANSFORM_ENABLE;
h264->fmoMode = NV_ENC_H264_FMO_DISABLE;
}
ctx->init_encode_params.enableEncodeAsync = 0;
ctx->init_encode_params.enablePTD = 1;
+ if (ctx->weighted_pred == 1)
+ ctx->init_encode_params.enableWeightedPrediction = 1;
+
if (ctx->bluray_compat) {
ctx->aud = 1;
avctx->refs = FFMIN(FFMAX(avctx->refs, 0), 6);
allocSurf.version = NV_ENC_CREATE_INPUT_BUFFER_VER;
allocSurf.width = (avctx->width + 31) & ~31;
allocSurf.height = (avctx->height + 31) & ~31;
- allocSurf.memoryHeap = NV_ENC_MEMORY_HEAP_SYSMEM_CACHED;
allocSurf.bufferFmt = ctx->surfaces[idx].format;
nv_status = p_nvenc->nvEncCreateInputBuffer(ctx->nvencoder, &allocSurf);
ctx->surfaces[idx].height = allocSurf.height;
}
- /* 1MB is large enough to hold most output frames.
- * NVENC increases this automaticaly if it is not enough. */
- allocOut.size = 1024 * 1024;
-
- allocOut.memoryHeap = NV_ENC_MEMORY_HEAP_SYSMEM_CACHED;
-
nv_status = p_nvenc->nvEncCreateBitstreamBuffer(ctx->nvencoder, &allocOut);
if (nv_status != NV_ENC_SUCCESS) {
int err = nvenc_print_error(avctx, nv_status, "CreateBitstreamBuffer failed");