summaryrefslogtreecommitdiff
path: root/libavcodec
diff options
context:
space:
mode:
authorHendrik Leppkes <h.leppkes@gmail.com>2015-10-10 09:58:42 +0200
committerHendrik Leppkes <h.leppkes@gmail.com>2015-10-10 09:58:42 +0200
commitc4e23ca8537701a38427f90b2dd72eb681d011d6 (patch)
tree7ba222709190ff263ada4a33c9d6d9fd3fc80a98 /libavcodec
parent80fd6225907d4f3e57a3c17944f5cf4edd1000cd (diff)
parentc3e5c47bdae2bb8219fea62d91b7455650b22c60 (diff)
Merge commit 'c3e5c47bdae2bb8219fea62d91b7455650b22c60'
* commit 'c3e5c47bdae2bb8219fea62d91b7455650b22c60': libopenh264enc: Added max_nal_size option Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/libopenh264enc.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 9603243fe3..01cf2522e4 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, &param) != cmResultSuccess) {
av_log(avctx, AV_LOG_ERROR, "Initialize failed\n");
goto fail;