From patchwork Thu Jan 5 16:14:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Zhili X-Patchwork-Id: 39879 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc95:b0:ad:ade2:bfd2 with SMTP id fx21csp206862pzb; Thu, 5 Jan 2023 00:15:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXtrQPHQAPm8E/G7z/rJ32qAB2VaKuPk1jj4YOQGv6kKvRKndzmKrayZcWCY9/zZS20j2IFQ X-Received: by 2002:a17:907:6d22:b0:7c1:52c:a960 with SMTP id sa34-20020a1709076d2200b007c1052ca960mr57893565ejc.8.1672906524607; Thu, 05 Jan 2023 00:15:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672906524; cv=none; d=google.com; s=arc-20160816; b=HIk8iN8zMGFAT4/Hubv+1reaNXN1wv+VpVcaWYUvd2mLk3fJ39C3su0qclaOme/E1S pDlNsQgHQDHu9Ey2McnPhHtwRsxUDLPVUpfZE48TR2Y89ZLdK11G97WBxZvXBHj1eZ/3 OksqIXW7Qwrx5Wuw2HGe7FcXfG7RAJ+KDek/9mmMvwuhI3zw3/jOUp7B3D29ltDlEtHA cI02HUovbw7BoC8Nz0WzjEossbfT0zIUaa285tB7eszm+cprGD0v1HdquQVJOEhMY5Ou Z8hzGBcMSwswfx/yGEWxLjXiDl686r2wDUsv0RXJTueiTa4J93ZxOu6hoo3KKSmzJ43+ 1d4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to:date :to:from:message-id:dkim-signature:delivered-to; bh=2DsZCPmTfZvGiufBn5Y8d3d24BAzDu9QoSvHso9BJ/0=; b=LQre0r0illZbuY6G6yDGUI7nIH3O/nP4XwLyE9+ZqU51RQiI2UnmsYuHGsPvNt3VnE 0b2VGswrZHnLsO41BTwglNJa3KpIdoRqqn3xkK6C7hQ1IDjhXDtD/MsSP3PjBgHkmdgL LkVFEkxlgRhCu+bAHCpJrH056zHzfQmbEj+S6c7uaGep0XBCgO9k5M7QeU8Eg/zpfK08 hQYUSCZk1/pZXqtOOK9PtNAjqcvj36hF9knMUpuWwbrB8gCwtjU03LBcyriZyI0u9KPf ba9oHvoXbD4tdGRpyYHbx1fU24l70RZB1fNn9PoPYdb/xCANVdY8T52SCeKRcrP919Ep Xqpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@foxmail.com header.s=s201512 header.b=N9cfETqx; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id dd21-20020a1709069b9500b007fed8db38a8si35530630ejc.114.2023.01.05.00.15.24; Thu, 05 Jan 2023 00:15:24 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@foxmail.com header.s=s201512 header.b=N9cfETqx; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4278E68BCC0; Thu, 5 Jan 2023 10:14:51 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out203-205-221-202.mail.qq.com (out203-205-221-202.mail.qq.com [203.205.221.202]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A691C68B752 for ; Thu, 5 Jan 2023 10:14:43 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1672906480; bh=ppcE7V+fIq3/Lx1xE28sEjSpaYVVLHD+gFerPaVzeY0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=N9cfETqxcnT2SHVaisvz4EsJ8Y7cjmMh2WJ8W2w/B4wbVmmvYVTNNl5Mojs/awc8a JZYN1yrzgxgMDtO0DrxiJlpL6YV/pNAX/yAhonQwyPyG1Ey1u8OJtMKlb2hOtAqXnj 6PrxEor7FAeqDidn0LYbGKcelhMpW8mfCuraW0mY= Received: from localhost.localdomain ([59.37.125.102]) by newxmesmtplogicsvrsza2-0.qq.com (NewEsmtp) with SMTP id 39F0DCCA; Thu, 05 Jan 2023 16:14:31 +0800 X-QQ-mid: xmsmtpt1672906474ts0ppfxpk Message-ID: X-QQ-XMAILINFO: OZZSS56D9fAjpTM4SEa2iYd6Zi1Ffc16NEIf+47I+OQXHtbXzqjAXzIJ6yBkDt jlc3cR+19GXxp7tGiwvswDIhBGVrkJWTojVDIfSn/ANk2PXvsrunfOepqe6b8QhWSWuOsVkN3rW9 OdzSMF+B0UyK/rA2nU5P/HlZmk2+pP2TxVo35+CPY/gsOe/zIaASWBZ75SbYMiB/XJ2/ewcrWnxM JB3S4x5gg/NDRr+zepL1TzRSpbtJ27JPt3DpsEkcLgTAsMFhYL6yJQjBP5qWnS7n9rLPa9ARVU80 W9VWe0+BXuPB0tN22LwjkiP3bAfDKA7yRh8vVr98gOT/6iy/BGPLuuCgJIerMZ/52qzzthiHN/Bu IGYM+jgyu6DB5nMVmPZz9f8tnE7MSf4PFgnXxfn3k8Z6/Vj3muX2HZniaqmi93g9U5bo8Z4QxPnw h64wc6T+Dkn3TUJHiIntlYWdVcXc3/GaA42IAI7GM6VcAfZN3LrhzvlqnFFf0LsD2jz1DkT0L12B MB7GswLsngub8oNrFtKyxyONHXNvCZqFlAj4ek88baA2AgrFTshE2hMoUyDyIXDH0gIjwaT+bE3i IMHnLsL+tbm/hmTDEbXDcKETvFtSVW+LxWybJs3KDZenp9QU7dFjfOitHlD3pyRnUg3uVKWL1fhn 5nPI3ksZ8pdG5YECl7puS94DtEJC/+M4WEISS143hu7bZdAjLQmgW8ad0t4I9b7YTYYbcclMjmQw r8BqYdT70JxO7sztNrezGfvww3Q9yh8r59H9G2Ibb8RUEGJo8X8005MJAWeGHWcq/kuxBFi/Rcfj sQkMGKj3yCwZ3A3gx8o5dI7/I7GH5+XQNIPDvkbJLEJGJxEqQ3NjqzGl1W2EWQwpmlsSpV7lbRHb d7P2H73F3p4ZyrujH7Yg4335aSSLqFWKmU+s3DlJdwzKKovWRGxtjAInIEiTKRPDv5Xn4KEmLUi0 Jx7zatcQMamgqRySEf+Qg+b9h2DR2IaAPkRLYu4ypRvcifd7KaCVebuwD8lvug From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Fri, 6 Jan 2023 00:14:16 +0800 X-OQ-MSGID: <20230105161416.194463-5-quinkblack@foxmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230105161416.194463-1-quinkblack@foxmail.com> References: <20230105161416.194463-1-quinkblack@foxmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [RFC PATCH 4/4] avcodec/h265_metadata_bsf: add nuh_layer_id option X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Zhao Zhili Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: N6/H5mDIGQht From: Zhao Zhili 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, \