diff options
author | Mario Gasparoni <mariogasparoni@gmail.com> | 2015-10-08 14:28:55 -0300 |
---|---|---|
committer | Luca Barbato <lu_zero@gentoo.org> | 2015-10-09 16:53:44 +0200 |
commit | c3e5c47bdae2bb8219fea62d91b7455650b22c60 (patch) | |
tree | bcaa8b328b41d78c479e27e4bb2908a90995304a | |
parent | 00cc10aee380f882507bac994ac469d8358d12e8 (diff) | |
download | ffmpeg-c3e5c47bdae2bb8219fea62d91b7455650b22c60.tar.gz |
libopenh264enc: Added max_nal_size option
Also added dynamic slice_mode option, needed for the max_nal_size.
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
-rw-r--r-- | libavcodec/libopenh264enc.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c index 0f18f80386..1553b6d52c 100644 --- a/libavcodec/libopenh264enc.c +++ b/libavcodec/libopenh264enc.c @@ -37,6 +37,7 @@ typedef struct SVCContext { int slice_mode; int loopfilter; char *profile; + int max_nal_size; } SVCContext; #define OPENH264_VER_AT_LEAST(maj, min) \ @@ -50,8 +51,10 @@ static const AVOption options[] = { { "fixed", "A fixed number of slices", 0, AV_OPT_TYPE_CONST, { .i64 = SM_FIXEDSLCNUM_SLICE }, 0, 0, VE, "slice_mode" }, { "rowmb", "One slice per row of macroblocks", 0, AV_OPT_TYPE_CONST, { .i64 = SM_ROWMB_SLICE }, 0, 0, VE, "slice_mode" }, { "auto", "Automatic number of slices according to number of threads", 0, AV_OPT_TYPE_CONST, { .i64 = SM_AUTO_SLICE }, 0, 0, VE, "slice_mode" }, + { "dyn", "Dynamic slicing", 0, AV_OPT_TYPE_CONST, { .i64 = SM_DYN_SLICE }, 0, 0, VE, "slice_mode" }, { "loopfilter", "Enable loop filter", OFFSET(loopfilter), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, VE }, { "profile", "Set profile restrictions", OFFSET(profile), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE }, + { "max_nal_size", "Set maximum NAL size in bytes", OFFSET(max_nal_size), AV_OPT_TYPE_INT, { 0 }, 0, INT_MAX, VE }, { NULL } }; @@ -165,11 +168,36 @@ static av_cold int svc_encode_init(AVCodecContext *avctx) param.sSpatialLayers[0].iSpatialBitrate = param.iTargetBitrate; param.sSpatialLayers[0].iMaxSpatialBitrate = param.iMaxBitrate; + if ((avctx->slices > 1) && (s->max_nal_size)){ + av_log(avctx,AV_LOG_ERROR,"Invalid combination -slices %d and -max_nal_size %d.\n",avctx->slices,s->max_nal_size); + goto fail; + } + if (avctx->slices > 1) s->slice_mode = SM_FIXEDSLCNUM_SLICE; + + if (s->max_nal_size) + s->slice_mode = SM_DYN_SLICE; + param.sSpatialLayers[0].sSliceCfg.uiSliceMode = s->slice_mode; param.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceNum = avctx->slices; + if (s->slice_mode == SM_DYN_SLICE) { + if (s->max_nal_size){ + param.uiMaxNalSize = s->max_nal_size; + param.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = s->max_nal_size; + } else { + if (avctx->rtp_payload_size) { + av_log(avctx,AV_LOG_DEBUG,"Using RTP Payload size for uiMaxNalSize"); + param.uiMaxNalSize = avctx->rtp_payload_size; + param.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = avctx->rtp_payload_size; + } else { + av_log(avctx,AV_LOG_ERROR,"Invalid -max_nal_size, specify a valid max_nal_size to use -slice_mode dyn\n"); + goto fail; + } + } + } + if ((*s->encoder)->InitializeExt(s->encoder, ¶m) != cmResultSuccess) { av_log(avctx, AV_LOG_ERROR, "Initialize failed\n"); goto fail; |