Ticket #9678: ffmpeg_nvenc_max_slice_size.patch

File ffmpeg_nvenc_max_slice_size.patch, 3.6 KB (added by Aleksoid1978, 3 years ago)

Updated patch for current git version.

  • libavcodec/nvenc.c

    diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
    index 06579a5..ed5bcf9 100644
    a b static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)  
    11661166        || vui->videoFormat != 5
    11671167        || vui->videoFullRangeFlag != 0);
    11681168
    1169     h264->sliceMode = 3;
    1170     h264->sliceModeData = avctx->slices > 0 ? avctx->slices : 1;
     1169    if (ctx->max_slice_size > 0) {
     1170        h264->sliceMode = 1;
     1171        h264->sliceModeData = ctx->max_slice_size;
     1172    } else {
     1173        h264->sliceMode = 3;
     1174        h264->sliceModeData = avctx->slices > 0 ? avctx->slices : 1;
     1175    }
    11711176
    11721177    if (ctx->intra_refresh) {
    11731178        h264->enableIntraRefresh = 1;
    static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx)  
    12901295        || vui->videoFormat != 5
    12911296        || vui->videoFullRangeFlag != 0);
    12921297
    1293     hevc->sliceMode = 3;
    1294     hevc->sliceModeData = avctx->slices > 0 ? avctx->slices : 1;
     1298    if (ctx->max_slice_size > 0) {
     1299        hevc->sliceMode = 1;
     1300        hevc->sliceModeData = ctx->max_slice_size;
     1301    } else {
     1302        hevc->sliceMode = 3;
     1303        hevc->sliceModeData = avctx->slices > 0 ? avctx->slices : 1;
     1304    }
    12951305
    12961306    if (ctx->intra_refresh) {
    12971307        hevc->enableIntraRefresh = 1;
  • libavcodec/nvenc.h

    diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
    index 3a4b456..cf0e8e5 100644
    a b typedef struct NvencContext  
    262262    int udu_sei;
    263263    int timing_info;
    264264    int highbitdepth;
     265    int max_slice_size;
    265266} NvencContext;
    266267
    267268int ff_nvenc_encode_init(AVCodecContext *avctx);
  • libavcodec/nvenc_h264.c

    diff --git a/libavcodec/nvenc_h264.c b/libavcodec/nvenc_h264.c
    index a998609..4440e49 100644
    a b static const AVOption options[] = {  
    206206                                                            OFFSET(intra_refresh),AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
    207207    { "single-slice-intra-refresh", "Use single slice intra refresh",
    208208                                                            OFFSET(single_slice_intra_refresh), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
     209    { "max_slice_size", "Maximum encoded slice size in bytes",
     210                                                            OFFSET(max_slice_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
    209211    { "constrained-encoding", "Enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices",
    210212                                                            OFFSET(constrained_encoding), AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
    211213    { NULL }
  • libavcodec/nvenc_hevc.c

    diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c
    index a02f277..e606655 100644
    a b static const AVOption options[] = {  
    187187                                                            OFFSET(intra_refresh),AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
    188188    { "single-slice-intra-refresh", "Use single slice intra refresh",
    189189                                                            OFFSET(single_slice_intra_refresh), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
     190    { "max_slice_size", "Maximum encoded slice size in bytes",
     191                                                            OFFSET(max_slice_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
    190192    { "constrained-encoding", "Enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices",
    191193                                                            OFFSET(constrained_encoding), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
    192194    { NULL }