* [FFmpeg-devel] [RFC PATCH 1/4] avcodec/hevc_parse: keep nal->nuh_layer_id > 0 [not found] <20230105161416.194463-1-quinkblack@foxmail.com> @ 2023-01-05 16:14 ` Zhao Zhili 2023-01-05 16:14 ` [FFmpeg-devel] [RFC PATCH 2/4] avcodec/cbs_h2645: " Zhao Zhili ` (2 subsequent siblings) 3 siblings, 0 replies; 9+ messages in thread From: Zhao Zhili @ 2023-01-05 16:14 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Zhao Zhili From: Zhao Zhili <zhilizhao@tencent.com> --- libavcodec/hevc_parse.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libavcodec/hevc_parse.c b/libavcodec/hevc_parse.c index 29dfd479f3..dddb293df6 100644 --- a/libavcodec/hevc_parse.c +++ b/libavcodec/hevc_parse.c @@ -37,8 +37,6 @@ static int hevc_decode_nal_units(const uint8_t *buf, int buf_size, HEVCParamSets for (i = 0; i < pkt.nb_nals; i++) { H2645NAL *nal = &pkt.nals[i]; - if (nal->nuh_layer_id > 0) - continue; /* ignore everything except parameter sets and VCL NALUs */ switch (nal->type) { -- 2.25.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] 9+ messages in thread
* [FFmpeg-devel] [RFC PATCH 2/4] avcodec/cbs_h2645: keep nal->nuh_layer_id > 0 [not found] <20230105161416.194463-1-quinkblack@foxmail.com> 2023-01-05 16:14 ` [FFmpeg-devel] [RFC PATCH 1/4] avcodec/hevc_parse: keep nal->nuh_layer_id > 0 Zhao Zhili @ 2023-01-05 16:14 ` Zhao Zhili 2023-01-05 11:18 ` James Almer 2023-01-05 16:14 ` [FFmpeg-devel] [RFC PATCH 3/4] avcodec/hevcdec: add nuh_layer_id option Zhao Zhili 2023-01-05 16:14 ` [FFmpeg-devel] [RFC PATCH 4/4] avcodec/h265_metadata_bsf: " Zhao Zhili 3 siblings, 1 reply; 9+ messages in thread From: Zhao Zhili @ 2023-01-05 16:14 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Zhao Zhili From: Zhao Zhili <zhilizhao@tencent.com> --- libavcodec/cbs_h2645.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 4ee06003c3..b12abede29 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -477,9 +477,6 @@ static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx, AVBufferRef *ref; size_t size = nal->size; - if (nal->nuh_layer_id > 0) - continue; - // Remove trailing zeroes. while (size > 0 && nal->data[size - 1] == 0) --size; -- 2.25.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] 9+ messages in thread
* Re: [FFmpeg-devel] [RFC PATCH 2/4] avcodec/cbs_h2645: keep nal->nuh_layer_id > 0 2023-01-05 16:14 ` [FFmpeg-devel] [RFC PATCH 2/4] avcodec/cbs_h2645: " Zhao Zhili @ 2023-01-05 11:18 ` James Almer 2023-01-05 12:06 ` "zhilizhao(赵志立)" 0 siblings, 1 reply; 9+ messages in thread From: James Almer @ 2023-01-05 11:18 UTC (permalink / raw) To: ffmpeg-devel On 1/5/2023 1:14 PM, Zhao Zhili wrote: > From: Zhao Zhili <zhilizhao@tencent.com> > > --- > libavcodec/cbs_h2645.c | 3 --- > 1 file changed, 3 deletions(-) > > diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c > index 4ee06003c3..b12abede29 100644 > --- a/libavcodec/cbs_h2645.c > +++ b/libavcodec/cbs_h2645.c > @@ -477,9 +477,6 @@ static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx, > AVBufferRef *ref; > size_t size = nal->size; > > - if (nal->nuh_layer_id > 0) > - continue; Have you tested samples with NALUs with a layer > 0? How does CBS handle them in both reading and writing? > - > // Remove trailing zeroes. > while (size > 0 && nal->data[size - 1] == 0) > --size; _______________________________________________ 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] 9+ messages in thread
* Re: [FFmpeg-devel] [RFC PATCH 2/4] avcodec/cbs_h2645: keep nal->nuh_layer_id > 0 2023-01-05 11:18 ` James Almer @ 2023-01-05 12:06 ` "zhilizhao(赵志立)" 0 siblings, 0 replies; 9+ messages in thread From: "zhilizhao(赵志立)" @ 2023-01-05 12:06 UTC (permalink / raw) To: FFmpeg development discussions and patches > On Jan 5, 2023, at 19:18, James Almer <jamrial@gmail.com> wrote: > > On 1/5/2023 1:14 PM, Zhao Zhili wrote: >> From: Zhao Zhili <zhilizhao@tencent.com> >> --- >> libavcodec/cbs_h2645.c | 3 --- >> 1 file changed, 3 deletions(-) >> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c >> index 4ee06003c3..b12abede29 100644 >> --- a/libavcodec/cbs_h2645.c >> +++ b/libavcodec/cbs_h2645.c >> @@ -477,9 +477,6 @@ static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx, >> AVBufferRef *ref; >> size_t size = nal->size; >> - if (nal->nuh_layer_id > 0) >> - continue; > > Have you tested samples with NALUs with a layer > 0? How does CBS handle them in both reading and writing? Yes, only with hevc alpha layer encoding. Both reading and writing work fine. What is missing is parse VPS extension, SEI alpha channel info and so on. Patch 4/4 rewrite nuh_layer_id from non-zero to zero, and it works from my test (for independent non-base layer). > >> - >> // Remove trailing zeroes. >> while (size > 0 && nal->data[size - 1] == 0) >> --size; > _______________________________________________ > 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". _______________________________________________ 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] 9+ messages in thread
* [FFmpeg-devel] [RFC PATCH 3/4] avcodec/hevcdec: add nuh_layer_id option [not found] <20230105161416.194463-1-quinkblack@foxmail.com> 2023-01-05 16:14 ` [FFmpeg-devel] [RFC PATCH 1/4] avcodec/hevc_parse: keep nal->nuh_layer_id > 0 Zhao Zhili 2023-01-05 16:14 ` [FFmpeg-devel] [RFC PATCH 2/4] avcodec/cbs_h2645: " Zhao Zhili @ 2023-01-05 16:14 ` Zhao Zhili 2023-01-05 11:21 ` James Almer 2023-01-05 16:14 ` [FFmpeg-devel] [RFC PATCH 4/4] avcodec/h265_metadata_bsf: " Zhao Zhili 3 siblings, 1 reply; 9+ messages in thread From: Zhao Zhili @ 2023-01-05 16:14 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Zhao Zhili From: Zhao Zhili <zhilizhao@tencent.com> It can be used to decode selected independent non-base layer. One use case is alpha layer decoding. Signed-off-by: Zhao Zhili <zhilizhao@tencent.com> --- libavcodec/hevcdec.c | 20 +++++++++++++++++++- libavcodec/version.h | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 567e8d81d4..9641922834 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -3216,7 +3216,8 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length) if (s->avctx->skip_frame >= AVDISCARD_ALL || (s->avctx->skip_frame >= AVDISCARD_NONREF - && ff_hevc_nal_is_nonref(nal->type)) || nal->nuh_layer_id > 0) + && ff_hevc_nal_is_nonref(nal->type)) || + nal->nuh_layer_id != s->nuh_layer_id) continue; ret = decode_nal_unit(s, nal); @@ -3637,6 +3638,21 @@ static av_cold int hevc_decode_init(AVCodecContext *avctx) HEVCContext *s = avctx->priv_data; int ret; + if (s->nuh_layer_id > 0) { + if (avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { + av_log(avctx, AV_LOG_ERROR, + "Decode selected nuh_layer_id is undef development. " + "Use -strict -2 to use it anyway.\n"); + return AVERROR(EINVAL); + } + + if (avctx->hwaccel) { + av_log(avctx, AV_LOG_ERROR, + "Decode selected nuh_layer_id doesn't work with hwaccel.\n"); + return AVERROR(EINVAL); + } + } + if (avctx->active_thread_type & FF_THREAD_SLICE) { s->threads_number = avctx->thread_count; ret = ff_slice_thread_init_progress(avctx); @@ -3691,6 +3707,8 @@ static const AVOption options[] = { AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR }, { "strict-displaywin", "stricly apply default display window size", OFFSET(apply_defdispwin), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR }, + { "nuh_layer_id", "Select which nuh_layer_id to decode (only works with INBL)", OFFSET(nuh_layer_id), + AV_OPT_TYPE_INT, {.i64 = 0}, 0, 62, PAR }, { NULL }, }; diff --git a/libavcodec/version.h b/libavcodec/version.h index 6b8a1dbb79..15f7c3fe3d 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -30,7 +30,7 @@ #include "version_major.h" #define LIBAVCODEC_VERSION_MINOR 56 -#define LIBAVCODEC_VERSION_MICRO 100 +#define LIBAVCODEC_VERSION_MICRO 101 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ -- 2.25.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] 9+ messages in thread
* Re: [FFmpeg-devel] [RFC PATCH 3/4] avcodec/hevcdec: add nuh_layer_id option 2023-01-05 16:14 ` [FFmpeg-devel] [RFC PATCH 3/4] avcodec/hevcdec: add nuh_layer_id option Zhao Zhili @ 2023-01-05 11:21 ` James Almer 2023-01-05 11:59 ` "zhilizhao(赵志立)" 0 siblings, 1 reply; 9+ messages in thread From: James Almer @ 2023-01-05 11:21 UTC (permalink / raw) To: ffmpeg-devel On 1/5/2023 1:14 PM, Zhao Zhili wrote: > From: Zhao Zhili <zhilizhao@tencent.com> > > It can be used to decode selected independent non-base layer. One > use case is alpha layer decoding. > > Signed-off-by: Zhao Zhili <zhilizhao@tencent.com> > --- > libavcodec/hevcdec.c | 20 +++++++++++++++++++- > libavcodec/version.h | 2 +- > 2 files changed, 20 insertions(+), 2 deletions(-) > > diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c > index 567e8d81d4..9641922834 100644 > --- a/libavcodec/hevcdec.c > +++ b/libavcodec/hevcdec.c > @@ -3216,7 +3216,8 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length) > > if (s->avctx->skip_frame >= AVDISCARD_ALL || > (s->avctx->skip_frame >= AVDISCARD_NONREF > - && ff_hevc_nal_is_nonref(nal->type)) || nal->nuh_layer_id > 0) > + && ff_hevc_nal_is_nonref(nal->type)) || > + nal->nuh_layer_id != s->nuh_layer_id) > continue; > > ret = decode_nal_unit(s, nal); > @@ -3637,6 +3638,21 @@ static av_cold int hevc_decode_init(AVCodecContext *avctx) > HEVCContext *s = avctx->priv_data; > int ret; > > + if (s->nuh_layer_id > 0) { > + if (avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { > + av_log(avctx, AV_LOG_ERROR, > + "Decode selected nuh_layer_id is undef development. " > + "Use -strict -2 to use it anyway.\n"); "Undef development"? Does decoding of these non-base layers work or not? One thing is something being experimental (thus known to be working in at least some cases, even if not spec compliant), and another is enabling something we don't know if it's going to work or not at all. > + return AVERROR(EINVAL); > + } > + > + if (avctx->hwaccel) { > + av_log(avctx, AV_LOG_ERROR, > + "Decode selected nuh_layer_id doesn't work with hwaccel.\n"); > + return AVERROR(EINVAL); > + } > + } > + > if (avctx->active_thread_type & FF_THREAD_SLICE) { > s->threads_number = avctx->thread_count; > ret = ff_slice_thread_init_progress(avctx); > @@ -3691,6 +3707,8 @@ static const AVOption options[] = { > AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR }, > { "strict-displaywin", "stricly apply default display window size", OFFSET(apply_defdispwin), > AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR }, > + { "nuh_layer_id", "Select which nuh_layer_id to decode (only works with INBL)", OFFSET(nuh_layer_id), > + AV_OPT_TYPE_INT, {.i64 = 0}, 0, 62, PAR }, > { NULL }, > }; > > diff --git a/libavcodec/version.h b/libavcodec/version.h > index 6b8a1dbb79..15f7c3fe3d 100644 > --- a/libavcodec/version.h > +++ b/libavcodec/version.h > @@ -30,7 +30,7 @@ > #include "version_major.h" > > #define LIBAVCODEC_VERSION_MINOR 56 > -#define LIBAVCODEC_VERSION_MICRO 100 > +#define LIBAVCODEC_VERSION_MICRO 101 > > #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ > LIBAVCODEC_VERSION_MINOR, \ _______________________________________________ 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] 9+ messages in thread
* Re: [FFmpeg-devel] [RFC PATCH 3/4] avcodec/hevcdec: add nuh_layer_id option 2023-01-05 11:21 ` James Almer @ 2023-01-05 11:59 ` "zhilizhao(赵志立)" 0 siblings, 0 replies; 9+ messages in thread From: "zhilizhao(赵志立)" @ 2023-01-05 11:59 UTC (permalink / raw) To: FFmpeg development discussions and patches > On Jan 5, 2023, at 19:21, James Almer <jamrial@gmail.com> wrote: > > On 1/5/2023 1:14 PM, Zhao Zhili wrote: >> From: Zhao Zhili <zhilizhao@tencent.com> >> It can be used to decode selected independent non-base layer. One >> use case is alpha layer decoding. >> Signed-off-by: Zhao Zhili <zhilizhao@tencent.com> >> --- >> libavcodec/hevcdec.c | 20 +++++++++++++++++++- >> libavcodec/version.h | 2 +- >> 2 files changed, 20 insertions(+), 2 deletions(-) >> diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c >> index 567e8d81d4..9641922834 100644 >> --- a/libavcodec/hevcdec.c >> +++ b/libavcodec/hevcdec.c >> @@ -3216,7 +3216,8 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length) >> if (s->avctx->skip_frame >= AVDISCARD_ALL || >> (s->avctx->skip_frame >= AVDISCARD_NONREF >> - && ff_hevc_nal_is_nonref(nal->type)) || nal->nuh_layer_id > 0) >> + && ff_hevc_nal_is_nonref(nal->type)) || >> + nal->nuh_layer_id != s->nuh_layer_id) >> continue; >> ret = decode_nal_unit(s, nal); >> @@ -3637,6 +3638,21 @@ static av_cold int hevc_decode_init(AVCodecContext *avctx) >> HEVCContext *s = avctx->priv_data; >> int ret; >> + if (s->nuh_layer_id > 0) { >> + if (avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { >> + av_log(avctx, AV_LOG_ERROR, >> + "Decode selected nuh_layer_id is undef development. " >> + "Use -strict -2 to use it anyway.\n"); > > "Undef development"? Does decoding of these non-base layers work or not? One thing is something being experimental (thus known to be working in at least some cases, even if not spec compliant), and another is enabling something we don't know if it's going to work or not at all. Undef -> Under. It works for INBL (independent non-base layer) bitstream, which is coded without using inter-layer prediction and conforms to a single layer profile. Apple’s "HEVC Video with Alpha Interoperability Profile” is this case from my test, although Apple doesn’t specify it clear. https://developer.apple.com/av-foundation/HEVC-Video-with-Alpha-Interoperability-Profile.pdf Whether it’s INBL can be checked from vps_extension, which doesn’t get parsed yet. There are at least three ways to add multi-layer extension support: 1. Fully support inside hevc soft decoder, with inter-layer prediction support, multiview and spatial scalability and so on. 2. A decoder wrapper, which has two or multi hevc decoder instances inside. Only works for INBL streams. 3. Let user handle multiple decoder instances. Only works from INBL streams. > >> + return AVERROR(EINVAL); >> + } >> + >> + if (avctx->hwaccel) { >> + av_log(avctx, AV_LOG_ERROR, >> + "Decode selected nuh_layer_id doesn't work with hwaccel.\n"); >> + return AVERROR(EINVAL); >> + } >> + } >> + >> if (avctx->active_thread_type & FF_THREAD_SLICE) { >> s->threads_number = avctx->thread_count; >> ret = ff_slice_thread_init_progress(avctx); >> @@ -3691,6 +3707,8 @@ static const AVOption options[] = { >> AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR }, >> { "strict-displaywin", "stricly apply default display window size", OFFSET(apply_defdispwin), >> AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, PAR }, >> + { "nuh_layer_id", "Select which nuh_layer_id to decode (only works with INBL)", OFFSET(nuh_layer_id), >> + AV_OPT_TYPE_INT, {.i64 = 0}, 0, 62, PAR }, >> { NULL }, >> }; >> diff --git a/libavcodec/version.h b/libavcodec/version.h >> index 6b8a1dbb79..15f7c3fe3d 100644 >> --- a/libavcodec/version.h >> +++ b/libavcodec/version.h >> @@ -30,7 +30,7 @@ >> #include "version_major.h" >> #define LIBAVCODEC_VERSION_MINOR 56 >> -#define LIBAVCODEC_VERSION_MICRO 100 >> +#define LIBAVCODEC_VERSION_MICRO 101 >> #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ >> LIBAVCODEC_VERSION_MINOR, \ > _______________________________________________ > 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". _______________________________________________ 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] 9+ messages in thread
* [FFmpeg-devel] [RFC PATCH 4/4] avcodec/h265_metadata_bsf: add nuh_layer_id option [not found] <20230105161416.194463-1-quinkblack@foxmail.com> ` (2 preceding siblings ...) 2023-01-05 16:14 ` [FFmpeg-devel] [RFC PATCH 3/4] avcodec/hevcdec: add nuh_layer_id option Zhao Zhili @ 2023-01-05 16:14 ` Zhao Zhili 2023-01-05 21:48 ` Mark Thompson 3 siblings, 1 reply; 9+ messages in thread From: Zhao Zhili @ 2023-01-05 16:14 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Zhao Zhili From: Zhao Zhili <zhilizhao@tencent.com> Extract NALUs with the specified nuh_layer_id and rewrite as base layer. For example, to extract alpha layer with nuh_layer_id equal to 1: ./ffmpeg -i alpha.mp4 \ -an -c:v copy \ -bsf:v hevc_mp4toannexb,hevc_metadata=nuh_layer_id=1 \ alpha.hevc --- doc/bitstream_filters.texi | 5 +++++ libavcodec/h265_metadata_bsf.c | 25 +++++++++++++++++++++++++ libavcodec/version.h | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi index c63c20370f..8cb5bee644 100644 --- a/doc/bitstream_filters.texi +++ b/doc/bitstream_filters.texi @@ -443,6 +443,11 @@ The argument must be the name of a level (for example, @samp{5.1}), a or the special name @samp{auto} indicating that the filter should attempt to guess the level from the input stream properties. +@item nuh_layer_id + +Extract NALUs with the specified nuh_layer_id and rewrite as base layer. +All other NALUs are dropped except VPS. + @end table @section hevc_mp4toannexb diff --git a/libavcodec/h265_metadata_bsf.c b/libavcodec/h265_metadata_bsf.c index 6787bd14a1..fdaab27186 100644 --- a/libavcodec/h265_metadata_bsf.c +++ b/libavcodec/h265_metadata_bsf.c @@ -62,6 +62,8 @@ typedef struct H265MetadataContext { int level; int level_guess; int level_warned; + + int nuh_layer_id; } H265MetadataContext; @@ -328,6 +330,25 @@ static int h265_metadata_update_fragment(AVBSFContext *bsf, AVPacket *pkt, H265MetadataContext *ctx = bsf->priv_data; int err, i; + if (ctx->nuh_layer_id >= 0) { + H265RawNALUnitHeader *header; + for (i = 0; i < au->nb_units; i++) { + if (au->units[i].type == HEVC_NAL_VPS) { + H265RawVPS *vps = au->units[i].content; + vps->vps_extension_flag = 0; + continue; + } + + header = au->units[i].content; + if (header->nuh_layer_id != ctx->nuh_layer_id) { + ff_cbs_delete_unit(au, i); + i--; + continue; + } + header->nuh_layer_id = 0; + } + } + // If an AUD is present, it must be the first NAL unit. if (au->nb_units && au->units[0].type == HEVC_NAL_AUD) { if (ctx->aud == BSF_ELEMENT_REMOVE) @@ -478,6 +499,10 @@ static const AVOption h265_metadata_options[] = { { LEVEL("8.5", 255) }, #undef LEVEL + { "nuh_layer_id", "Extract NALUs with the specified nuh_layer_id and rewrite as base layer", + OFFSET(nuh_layer_id), AV_OPT_TYPE_INT, + { .i64 = -1 }, -1, 62, FLAGS }, + { NULL } }; diff --git a/libavcodec/version.h b/libavcodec/version.h index 15f7c3fe3d..734a4fe097 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -30,7 +30,7 @@ #include "version_major.h" #define LIBAVCODEC_VERSION_MINOR 56 -#define LIBAVCODEC_VERSION_MICRO 101 +#define LIBAVCODEC_VERSION_MICRO 102 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ -- 2.25.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] 9+ messages in thread
* Re: [FFmpeg-devel] [RFC PATCH 4/4] avcodec/h265_metadata_bsf: add nuh_layer_id option 2023-01-05 16:14 ` [FFmpeg-devel] [RFC PATCH 4/4] avcodec/h265_metadata_bsf: " Zhao Zhili @ 2023-01-05 21:48 ` Mark Thompson 0 siblings, 0 replies; 9+ messages in thread From: Mark Thompson @ 2023-01-05 21:48 UTC (permalink / raw) To: ffmpeg-devel On 05/01/2023 16:14, Zhao Zhili wrote: > From: Zhao Zhili <zhilizhao@tencent.com> > > Extract NALUs with the specified nuh_layer_id and rewrite as base > layer. For example, to extract alpha layer with nuh_layer_id equal > to 1: > > ./ffmpeg -i alpha.mp4 \ > -an -c:v copy \ > -bsf:v hevc_mp4toannexb,hevc_metadata=nuh_layer_id=1 \ > alpha.hevc > --- > doc/bitstream_filters.texi | 5 +++++ > libavcodec/h265_metadata_bsf.c | 25 +++++++++++++++++++++++++ > libavcodec/version.h | 2 +- > 3 files changed, 31 insertions(+), 1 deletion(-) Rest of series looks sensible to me. This doesn't have anything to do with metadata, though? IMO make a new BSF (extractlayer?) for this; the amount of boilerplate is quite small. > diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi > index c63c20370f..8cb5bee644 100644 > --- a/doc/bitstream_filters.texi > +++ b/doc/bitstream_filters.texi > @@ -443,6 +443,11 @@ The argument must be the name of a level (for example, @samp{5.1}), a > or the special name @samp{auto} indicating that the filter should > attempt to guess the level from the input stream properties. > > +@item nuh_layer_id > + > +Extract NALUs with the specified nuh_layer_id and rewrite as base layer. > +All other NALUs are dropped except VPS. > + > @end table > > @section hevc_mp4toannexb > diff --git a/libavcodec/h265_metadata_bsf.c b/libavcodec/h265_metadata_bsf.c > index 6787bd14a1..fdaab27186 100644 > --- a/libavcodec/h265_metadata_bsf.c > +++ b/libavcodec/h265_metadata_bsf.c > @@ -62,6 +62,8 @@ typedef struct H265MetadataContext { > int level; > int level_guess; > int level_warned; > + > + int nuh_layer_id; > } H265MetadataContext; > > > @@ -328,6 +330,25 @@ static int h265_metadata_update_fragment(AVBSFContext *bsf, AVPacket *pkt, > H265MetadataContext *ctx = bsf->priv_data; > int err, i; > > + if (ctx->nuh_layer_id >= 0) { > + H265RawNALUnitHeader *header; > + for (i = 0; i < au->nb_units; i++) { > + if (au->units[i].type == HEVC_NAL_VPS) { > + H265RawVPS *vps = au->units[i].content; > + vps->vps_extension_flag = 0; > + continue; > + } What is this change doing? Does the VPS also need to be edited to fix the layer references? (The intended input presumably has a VPS saying there are two layers which are both included, but after this change there aren't.) > + > + header = au->units[i].content; > + if (header->nuh_layer_id != ctx->nuh_layer_id) { > + ff_cbs_delete_unit(au, i); > + i--; > + continue; > + } > + header->nuh_layer_id = 0; > + } > + } Not required, but some error messages for bad cases would be nice - you can know from the VPS if the asked-for layer doesn't exist at all and stop early, and you can know later that there was no output and warn the user about it (bonus points if you also tell them which layers are present!). > + > // If an AUD is present, it must be the first NAL unit. > if (au->nb_units && au->units[0].type == HEVC_NAL_AUD) { > if (ctx->aud == BSF_ELEMENT_REMOVE) > @@ -478,6 +499,10 @@ static const AVOption h265_metadata_options[] = { > { LEVEL("8.5", 255) }, > #undef LEVEL > > + { "nuh_layer_id", "Extract NALUs with the specified nuh_layer_id and rewrite as base layer", > + OFFSET(nuh_layer_id), AV_OPT_TYPE_INT, > + { .i64 = -1 }, -1, 62, FLAGS }, > + > { NULL } > }; Thanks, - Mark _______________________________________________ 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] 9+ messages in thread
end of thread, other threads:[~2023-01-05 21:49 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <20230105161416.194463-1-quinkblack@foxmail.com> 2023-01-05 16:14 ` [FFmpeg-devel] [RFC PATCH 1/4] avcodec/hevc_parse: keep nal->nuh_layer_id > 0 Zhao Zhili 2023-01-05 16:14 ` [FFmpeg-devel] [RFC PATCH 2/4] avcodec/cbs_h2645: " Zhao Zhili 2023-01-05 11:18 ` James Almer 2023-01-05 12:06 ` "zhilizhao(赵志立)" 2023-01-05 16:14 ` [FFmpeg-devel] [RFC PATCH 3/4] avcodec/hevcdec: add nuh_layer_id option Zhao Zhili 2023-01-05 11:21 ` James Almer 2023-01-05 11:59 ` "zhilizhao(赵志立)" 2023-01-05 16:14 ` [FFmpeg-devel] [RFC PATCH 4/4] avcodec/h265_metadata_bsf: " Zhao Zhili 2023-01-05 21:48 ` Mark Thompson
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