From: Zhao Zhili <quinkblack@foxmail.com> To: ffmpeg-devel@ffmpeg.org Cc: Zhao Zhili <zhilizhao@tencent.com> Subject: [FFmpeg-devel] [RFC PATCH] avcodec/nvenc: add alpha layer encoding support Date: Sat, 31 Dec 2022 01:50:19 +0800 Message-ID: <tencent_E0CDAECFC0550E2778B890163D4D39201F07@qq.com> (raw) From: Zhao Zhili <zhilizhao@tencent.com> Signed-off-by: Zhao Zhili <zhilizhao@tencent.com> --- I need help. A lot of things doesn't work as Nvidia's doc: 1. Global header is broken. NV_ENC_SEQUENCE_PARAM_PAYLOAD doesn't work with multi SPS/PPS. It output VPS, SPS_0, SPS_1, PPS_0, with PPS_1 missing. 2. NV_ENC_LOCK_BITSTREAM.alphaLayerSizeInBytes is always 0, although the data is there. 3. The alpha layer bitstream is corrupted. It can be decoded with a lot of errors. libavcodec/nvenc.c | 13 +++++++++++++ libavcodec/nvenc.h | 1 + libavcodec/nvenc_hevc.c | 2 ++ 3 files changed, 16 insertions(+) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index f6df7cb6ac..e46cea4302 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -578,6 +578,12 @@ static int nvenc_check_capabilities(AVCodecContext *avctx) return AVERROR(ENOSYS); } + if (ctx->alpha_bitrate_ratio > 0 && + nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_ALPHA_LAYER_ENCODING) <= 0) { + av_log(avctx, AV_LOG_ERROR, "Alpha layer encoding not supported\n"); + return AVERROR(ENOSYS); + } + ctx->support_dyn_bitrate = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_DYN_BITRATE_CHANGE); return 0; @@ -1290,6 +1296,13 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx) hevc->enableConstrainedEncoding = 1; #endif + if (ctx->alpha_bitrate_ratio > 0 && (pixdesc->flags & AV_PIX_FMT_FLAG_ALPHA)) { + hevc->enableAlphaLayerEncoding = 1; + cc->rcParams.alphaLayerBitrateRatio = ctx->alpha_bitrate_ratio; + av_log(avctx, AV_LOG_DEBUG, "Enable alpha layer encoding for pix_fmt %s\n", + pixdesc->name); + } + hevc->disableSPSPPS = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 1 : 0; hevc->repeatSPSPPS = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 0 : 1; hevc->outputAUD = ctx->aud; diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h index 05a7ac48b1..f210d71eeb 100644 --- a/libavcodec/nvenc.h +++ b/libavcodec/nvenc.h @@ -240,6 +240,7 @@ typedef struct NvencContext int udu_sei; int timing_info; int highbitdepth; + int alpha_bitrate_ratio; } NvencContext; int ff_nvenc_encode_init(AVCodecContext *avctx); diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c index 5ad423444a..67a649fad2 100644 --- a/libavcodec/nvenc_hevc.c +++ b/libavcodec/nvenc_hevc.c @@ -177,6 +177,8 @@ static const AVOption options[] = { OFFSET(single_slice_intra_refresh), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, { "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 }, + { "alpha-bitrate-ratio", "Specifies the ratio in which bitrate should be split between base and alpha layer, 0 for disable alpha layer encoding", + OFFSET(alpha_bitrate_ratio), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE }, { NULL } }; -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next reply other threads:[~2022-12-30 17:50 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-12-30 17:50 Zhao Zhili [this message] 2022-12-30 18:42 ` Timo Rothenpieler
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=tencent_E0CDAECFC0550E2778B890163D4D39201F07@qq.com \ --to=quinkblack@foxmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ --cc=zhilizhao@tencent.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git