Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Zhao Zhili <quinkblack@foxmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Zhao Zhili <zhilizhao@tencent.com>
Subject: [FFmpeg-devel] [RFC PATCH 4/4] avcodec/h265_metadata_bsf: add nuh_layer_id option
Date: Fri,  6 Jan 2023 00:14:16 +0800
Message-ID: <tencent_BAB52868EE00616AE27E5AAC2A391DC37D0A@qq.com> (raw)
In-Reply-To: <20230105161416.194463-1-quinkblack@foxmail.com>

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".

  parent reply	other threads:[~2023-01-05  8:15 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 ` Zhao Zhili [this message]
2023-01-05 21:48   ` [FFmpeg-devel] [RFC PATCH 4/4] avcodec/h265_metadata_bsf: " Mark Thompson

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_BAB52868EE00616AE27E5AAC2A391DC37D0A@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