@@ -578,6 +578,12 @@ static int nvenc_check_capabilities(AVCodecContext *avctx)
return AVERROR(ENOSYS);
}
+ if (ctx->alpha_bitrate_ratio > 0 &&
+ nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_ALPHA_LAYER_ENCODING) <= 0) {
+ av_log(avctx, AV_LOG_ERROR, "Alpha layer encoding not supported\n");
+ return AVERROR(ENOSYS);
+ }
+
ctx->support_dyn_bitrate = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_DYN_BITRATE_CHANGE);
return 0;
@@ -1290,6 +1296,13 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx)
hevc->enableConstrainedEncoding = 1;
#endif
+ if (ctx->alpha_bitrate_ratio > 0 && (pixdesc->flags & AV_PIX_FMT_FLAG_ALPHA)) {
+ hevc->enableAlphaLayerEncoding = 1;
+ cc->rcParams.alphaLayerBitrateRatio = ctx->alpha_bitrate_ratio;
+ av_log(avctx, AV_LOG_DEBUG, "Enable alpha layer encoding for pix_fmt %s\n",
+ pixdesc->name);
+ }
+
hevc->disableSPSPPS = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 1 : 0;
hevc->repeatSPSPPS = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 0 : 1;
hevc->outputAUD = ctx->aud;
@@ -240,6 +240,7 @@ typedef struct NvencContext
int udu_sei;
int timing_info;
int highbitdepth;
+ int alpha_bitrate_ratio;
} NvencContext;
int ff_nvenc_encode_init(AVCodecContext *avctx);
@@ -177,6 +177,8 @@ static const AVOption options[] = {
OFFSET(single_slice_intra_refresh), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ "constrained-encoding", "Enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices",
OFFSET(constrained_encoding), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
+ { "alpha-bitrate-ratio", "Specifies the ratio in which bitrate should be split between base and alpha layer, 0 for disable alpha layer encoding",
+ OFFSET(alpha_bitrate_ratio), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
{ NULL }
};