* [FFmpeg-devel] [RFC PATCH] avcodec/nvenc: add alpha layer encoding support
@ 2022-12-30 17:50 Zhao Zhili
2022-12-30 18:42 ` Timo Rothenpieler
0 siblings, 1 reply; 2+ messages in thread
From: Zhao Zhili @ 2022-12-30 17:50 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Zhao Zhili
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".
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [FFmpeg-devel] [RFC PATCH] avcodec/nvenc: add alpha layer encoding support
2022-12-30 17:50 [FFmpeg-devel] [RFC PATCH] avcodec/nvenc: add alpha layer encoding support Zhao Zhili
@ 2022-12-30 18:42 ` Timo Rothenpieler
0 siblings, 0 replies; 2+ messages in thread
From: Timo Rothenpieler @ 2022-12-30 18:42 UTC (permalink / raw)
To: ffmpeg-devel
On 30.12.2022 18:50, Zhao Zhili wrote:
> 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.
I had played around with this before as well:>
https://github.com/BtbN/FFmpeg/commit/589f96f2a3fb0cc719d76555f09f1bc1e8cb0403
But my conclusion was similar. The feature seems to be half broken and
on top of that poorly specified.
I eventually gave up investigating and just concluded it was broken.
_______________________________________________
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".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-12-30 18:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-30 17:50 [FFmpeg-devel] [RFC PATCH] avcodec/nvenc: add alpha layer encoding support Zhao Zhili
2022-12-30 18:42 ` Timo Rothenpieler
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