From: Mark Thompson <sw@jkqxz.net> To: ffmpeg-devel@ffmpeg.org Subject: Re: [FFmpeg-devel] [RFC PATCH 4/4] avcodec/h265_metadata_bsf: add nuh_layer_id option Date: Thu, 5 Jan 2023 21:48:38 +0000 Message-ID: <e61449d2-afc3-8245-a7d0-d84abb0efb38@jkqxz.net> (raw) In-Reply-To: <tencent_BAB52868EE00616AE27E5AAC2A391DC37D0A@qq.com> 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".
prev parent reply other threads:[~2023-01-05 21:49 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top [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 [this message]
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=e61449d2-afc3-8245-a7d0-d84abb0efb38@jkqxz.net \ --to=sw@jkqxz.net \ --cc=ffmpeg-devel@ffmpeg.org \ /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