Skip to content

Commit

Permalink
avcodec/nvenc: Add options for level and tier
Browse files Browse the repository at this point in the history
  • Loading branch information
BtbN committed Apr 3, 2015
1 parent acbb904 commit 4119dbe
Showing 1 changed file with 125 additions and 1 deletion.
126 changes: 125 additions & 1 deletion libavcodec/nvenc.c
Expand Up @@ -152,6 +152,8 @@ typedef struct NvencContext

char *preset;
char *profile;
char *level;
char *tier;
int cbr;
int twopass;
int gpu;
Expand Down Expand Up @@ -777,6 +779,63 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
goto error;
}
}

if (ctx->level) {
if (!strcmp(ctx->profile, "auto")) {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_AUTOSELECT;
} else if (!strcmp(ctx->profile, "1")) {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_H264_1;
} else if (!strcmp(ctx->profile, "1.0")) {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_H264_1;
} else if (!strcmp(ctx->profile, "1b")) {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_H264_1b;
} else if (!strcmp(ctx->profile, "1.0b")) {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_H264_1b;
} else if (!strcmp(ctx->profile, "1.1")) {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_H264_11;
} else if (!strcmp(ctx->profile, "1.2")) {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_H264_12;
} else if (!strcmp(ctx->profile, "1.3")) {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_H264_13;
} else if (!strcmp(ctx->profile, "2")) {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_H264_2;
} else if (!strcmp(ctx->profile, "2.0")) {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_H264_2;
} else if (!strcmp(ctx->profile, "2.1")) {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_H264_21;
} else if (!strcmp(ctx->profile, "2.2")) {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_H264_22;
} else if (!strcmp(ctx->profile, "3")) {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_H264_3;
} else if (!strcmp(ctx->profile, "3.0")) {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_H264_3;
} else if (!strcmp(ctx->profile, "3.1")) {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_H264_31;
} else if (!strcmp(ctx->profile, "3.2")) {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_H264_32;
} else if (!strcmp(ctx->profile, "4")) {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_H264_4;
} else if (!strcmp(ctx->profile, "4.0")) {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_H264_4;
} else if (!strcmp(ctx->profile, "4.1")) {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_H264_41;
} else if (!strcmp(ctx->profile, "4.2")) {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_H264_42;
} else if (!strcmp(ctx->profile, "5")) {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_H264_5;
} else if (!strcmp(ctx->profile, "5.0")) {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_H264_5;
} else if (!strcmp(ctx->profile, "5.1")) {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_H264_51;
} else {
av_log(avctx, AV_LOG_FATAL, "Level \"%s\" is unknown! Supported levels: auto, 1, 1b, 1.1, 1.2, 1.3, 2, 2.1, 2.2, 3, 3.1, 3.2, 4, 4.1, 4.2, 5, 5.1\n", ctx->level);
res = AVERROR(EINVAL);
goto error;
}
} else {
ctx->encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_AUTOSELECT;
}

break;
case AV_CODEC_ID_H265:
ctx->encode_config.encodeCodecConfig.hevcConfig.disableSPSPPS = (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) ? 1 : 0;
Expand All @@ -785,6 +844,69 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
/* No other profile is supported in the current SDK version 5 */
ctx->encode_config.profileGUID = NV_ENC_HEVC_PROFILE_MAIN_GUID;
avctx->profile = FF_PROFILE_HEVC_MAIN;

if (ctx->level) {
if (!strcmp(ctx->profile, "auto")) {
ctx->encode_config.encodeCodecConfig.hevcConfig.level = NV_ENC_LEVEL_AUTOSELECT;
} else if (!strcmp(ctx->profile, "1")) {
ctx->encode_config.encodeCodecConfig.hevcConfig.level = NV_ENC_LEVEL_HEVC_1;
} else if (!strcmp(ctx->profile, "1.0")) {
ctx->encode_config.encodeCodecConfig.hevcConfig.level = NV_ENC_LEVEL_HEVC_1;
} else if (!strcmp(ctx->profile, "2")) {
ctx->encode_config.encodeCodecConfig.hevcConfig.level = NV_ENC_LEVEL_HEVC_2;
} else if (!strcmp(ctx->profile, "2.0")) {
ctx->encode_config.encodeCodecConfig.hevcConfig.level = NV_ENC_LEVEL_HEVC_2;
} else if (!strcmp(ctx->profile, "2.1")) {
ctx->encode_config.encodeCodecConfig.hevcConfig.level = NV_ENC_LEVEL_HEVC_21;
} else if (!strcmp(ctx->profile, "3")) {
ctx->encode_config.encodeCodecConfig.hevcConfig.level = NV_ENC_LEVEL_HEVC_3;
} else if (!strcmp(ctx->profile, "3.0")) {
ctx->encode_config.encodeCodecConfig.hevcConfig.level = NV_ENC_LEVEL_HEVC_3;
} else if (!strcmp(ctx->profile, "3.1")) {
ctx->encode_config.encodeCodecConfig.hevcConfig.level = NV_ENC_LEVEL_HEVC_31;
} else if (!strcmp(ctx->profile, "4")) {
ctx->encode_config.encodeCodecConfig.hevcConfig.level = NV_ENC_LEVEL_HEVC_4;
} else if (!strcmp(ctx->profile, "4.0")) {
ctx->encode_config.encodeCodecConfig.hevcConfig.level = NV_ENC_LEVEL_HEVC_4;
} else if (!strcmp(ctx->profile, "4.1")) {
ctx->encode_config.encodeCodecConfig.hevcConfig.level = NV_ENC_LEVEL_HEVC_41;
} else if (!strcmp(ctx->profile, "5")) {
ctx->encode_config.encodeCodecConfig.hevcConfig.level = NV_ENC_LEVEL_HEVC_5;
} else if (!strcmp(ctx->profile, "5.0")) {
ctx->encode_config.encodeCodecConfig.hevcConfig.level = NV_ENC_LEVEL_HEVC_5;
} else if (!strcmp(ctx->profile, "5.1")) {
ctx->encode_config.encodeCodecConfig.hevcConfig.level = NV_ENC_LEVEL_HEVC_51;
} else if (!strcmp(ctx->profile, "5.2")) {
ctx->encode_config.encodeCodecConfig.hevcConfig.level = NV_ENC_LEVEL_HEVC_52;
} else if (!strcmp(ctx->profile, "6")) {
ctx->encode_config.encodeCodecConfig.hevcConfig.level = NV_ENC_LEVEL_HEVC_6;
} else if (!strcmp(ctx->profile, "6.0")) {
ctx->encode_config.encodeCodecConfig.hevcConfig.level = NV_ENC_LEVEL_HEVC_6;
} else if (!strcmp(ctx->profile, "6.1")) {
ctx->encode_config.encodeCodecConfig.hevcConfig.level = NV_ENC_LEVEL_HEVC_61;
} else if (!strcmp(ctx->profile, "6.2")) {
ctx->encode_config.encodeCodecConfig.hevcConfig.level = NV_ENC_LEVEL_HEVC_62;
} else {
av_log(avctx, AV_LOG_FATAL, "Level \"%s\" is unknown! Supported levels: auto, 1, 2, 2.1, 3, 3.1, 4, 4.1, 5, 5.1, 5.2, 6, 6.1, 6.2\n", ctx->level);
res = AVERROR(EINVAL);
goto error;
}
} else {
ctx->encode_config.encodeCodecConfig.hevcConfig.level = NV_ENC_LEVEL_AUTOSELECT;
}

if (ctx->tier) {
if (!strcmp(ctx->tier, "main")) {
ctx->encode_config.encodeCodecConfig.hevcConfig.tier = NV_ENC_TIER_HEVC_MAIN;
} else if (!strcmp(ctx->tier, "high")) {
ctx->encode_config.encodeCodecConfig.hevcConfig.tier = NV_ENC_TIER_HEVC_HIGH;
} else {
av_log(avctx, AV_LOG_FATAL, "Tier \"%s\" is unknown! Supported tiers: main, high\n", ctx->tier);
res = AVERROR(EINVAL);
goto error;
}
}

break;
/* Earlier switch/case will return if unknown codec is passed. */
}
Expand Down Expand Up @@ -1277,7 +1399,9 @@ static enum AVPixelFormat pix_fmts_nvenc[] = {
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
static const AVOption options[] = {
{ "preset", "Set the encoding preset (one of hq, hp, bd, ll, llhq, llhp, default)", OFFSET(preset), AV_OPT_TYPE_STRING, { .str = "hq" }, 0, 0, VE },
{ "profile", "Set the encoding profile (high, main or baseline)", OFFSET(profile), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
{ "profile", "Set the encoding profile (high, main or baseline)", OFFSET(profile), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
{ "level", "Set the encoding level restriction (auto, 1.0, 1.0b, 1.1, 1.2, ..., 4.2, 5.0, 5.1)", OFFSET(level), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
{ "tier", "Set the encoding tier (main or high)", OFFSET(tier), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
{ "cbr", "Use cbr encoding mode", OFFSET(cbr), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
{ "2pass", "Use 2pass cbr encoding mode (low latency mode only)", OFFSET(twopass), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE },
{ "gpu", "Selects which NVENC capable GPU to use. First GPU is 0, second is 1, and so on.", OFFSET(gpu), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
Expand Down

0 comments on commit 4119dbe

Please sign in to comment.