avcodec/nvenc: add option to limit slice size

This commit is contained in:
Aleksoid 2023-07-27 12:26:23 +10:00 committed by Timo Rothenpieler
parent 95433eb3aa
commit 7eb0d9e905
4 changed files with 19 additions and 4 deletions

View File

@ -1166,8 +1166,13 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)
|| vui->videoFormat != 5 || vui->videoFormat != 5
|| vui->videoFullRangeFlag != 0); || vui->videoFullRangeFlag != 0);
h264->sliceMode = 3; if (ctx->max_slice_size > 0) {
h264->sliceModeData = avctx->slices > 0 ? avctx->slices : 1; h264->sliceMode = 1;
h264->sliceModeData = ctx->max_slice_size;
} else {
h264->sliceMode = 3;
h264->sliceModeData = avctx->slices > 0 ? avctx->slices : 1;
}
if (ctx->intra_refresh) { if (ctx->intra_refresh) {
h264->enableIntraRefresh = 1; h264->enableIntraRefresh = 1;
@ -1287,8 +1292,13 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx)
|| vui->videoFormat != 5 || vui->videoFormat != 5
|| vui->videoFullRangeFlag != 0); || vui->videoFullRangeFlag != 0);
hevc->sliceMode = 3; if (ctx->max_slice_size > 0) {
hevc->sliceModeData = avctx->slices > 0 ? avctx->slices : 1; hevc->sliceMode = 1;
hevc->sliceModeData = ctx->max_slice_size;
} else {
hevc->sliceMode = 3;
hevc->sliceModeData = avctx->slices > 0 ? avctx->slices : 1;
}
if (ctx->intra_refresh) { if (ctx->intra_refresh) {
hevc->enableIntraRefresh = 1; hevc->enableIntraRefresh = 1;

View File

@ -262,6 +262,7 @@ typedef struct NvencContext
int udu_sei; int udu_sei;
int timing_info; int timing_info;
int highbitdepth; int highbitdepth;
int max_slice_size;
} NvencContext; } NvencContext;
int ff_nvenc_encode_init(AVCodecContext *avctx); int ff_nvenc_encode_init(AVCodecContext *avctx);

View File

@ -206,6 +206,8 @@ static const AVOption options[] = {
OFFSET(intra_refresh),AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, OFFSET(intra_refresh),AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ "single-slice-intra-refresh", "Use single slice intra refresh", { "single-slice-intra-refresh", "Use single slice intra refresh",
OFFSET(single_slice_intra_refresh), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, OFFSET(single_slice_intra_refresh), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ "max_slice_size", "Maximum encoded slice size in bytes",
OFFSET(max_slice_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
{ "constrained-encoding", "Enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices", { "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 }, OFFSET(constrained_encoding), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ NULL } { NULL }

View File

@ -187,6 +187,8 @@ static const AVOption options[] = {
OFFSET(intra_refresh),AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, OFFSET(intra_refresh),AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ "single-slice-intra-refresh", "Use single slice intra refresh", { "single-slice-intra-refresh", "Use single slice intra refresh",
OFFSET(single_slice_intra_refresh), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, OFFSET(single_slice_intra_refresh), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ "max_slice_size", "Maximum encoded slice size in bytes",
OFFSET(max_slice_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
{ "constrained-encoding", "Enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices", { "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 }, OFFSET(constrained_encoding), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ NULL } { NULL }