From patchwork Sat Feb 4 10:06:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gyan Doshi X-Patchwork-Id: 40245 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:5494:b0:bf:7b3a:fd32 with SMTP id i20csp1853059pzk; Sat, 4 Feb 2023 02:07:38 -0800 (PST) X-Google-Smtp-Source: AK7set/7q/a4fLLteQTGDnUQTmL6URtrxNdBf8TAhSwfdT7nOOISjI8/trxkqqCHfLo5LTn0zRTC X-Received: by 2002:a17:907:c29:b0:895:58be:96b with SMTP id ga41-20020a1709070c2900b0089558be096bmr904186ejc.3.1675505258488; Sat, 04 Feb 2023 02:07:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675505258; cv=none; d=google.com; s=arc-20160816; b=n81sGQzwXD5GjI/seuSU/DdWmmdZMh1TItEWMoNZOdePR9oRhhN1ECsQXjKLldOmYs 4TkUzPjQVQ8xkPqpu0LDRP642Gf/cXRTpuhMpMEePka3sUvhWAP8jQd1jLTJK3I0+0W5 8EaVs2zy1ZTr5mxwI1I1gRQr3IXeq7TV12A65X5Rjs4PGyNSW3QbWOw5Bh2JX9BgMzcr /KLRI2HEq9sBJpTT92zjkeyPIHr37I1y1veu6/aUjwW8KSU+fFAiRofaiFI8Z4M/YB+l LwXIA3oDV0DruhULiGWVXciFLtQGOCSiTwLWxNd3FOCGBZgfGSaVmlnBLrEfUgPU5Sqw r6Ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=T5m6gyBzgxi3o9k3QZEBpmN/apmNZSMDOsjZlBPRGMk=; b=ypKpIb6J8iel7JZwcCXxK2tOnuTYNhDlYsL42wlLzsBdh1zAoPUchpp5gj+4kKXeAu WNvvKzFYBMkCjEg/WOAWrqCnW5zbv2qZtbMrxoGF5Or8Shci0WyBWOwp8C7/IscNfI4M O+N/0Ec5bZrynyJIcjx4Cmn4caVVsW2hB7fy+6RQwrcbKX95y0N5IrbCeGRyMbEKrpfN mLRxn83+CST7enQwQEZIi/DNHAa1YgBP8CEcR9r9PmczYOXu9UoK3bY59tYhOgSqoUcn 46c1AyUlj6zowrgnIQ3Bol72omRgB506m4qqQ9LcVQucbSBqL4c/5fGoI419rytSea2w 8osg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id bp14-20020a170907918e00b008951f8a8b5csi703016ejb.161.2023.02.04.02.07.38; Sat, 04 Feb 2023 02:07:38 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5982768BE22; Sat, 4 Feb 2023 12:07:35 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 66A7068B934 for ; Sat, 4 Feb 2023 12:07:28 +0200 (EET) Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4P87Vj6Lk4z9sSx for ; Sat, 4 Feb 2023 11:07:25 +0100 (CET) From: Gyan Doshi To: ffmpeg-devel@ffmpeg.org Date: Sat, 4 Feb 2023 15:36:57 +0530 Message-Id: <20230204100657.6882-1-ffmpeg@gyani.pro> In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4P87Vj6Lk4z9sSx Subject: [FFmpeg-devel] [PATCH v2] avcodec/h264_metadata_bsf: remove AUDs at any position 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ER7Q0Z46ia4w Some files, likely due to faulty packetization or muxing, can have AUDs at other positions besides the head unit of a packet. Remove these too. --- libavcodec/h264_metadata_bsf.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c index d318bf0cee..b9cfeaba94 100644 --- a/libavcodec/h264_metadata_bsf.c +++ b/libavcodec/h264_metadata_bsf.c @@ -469,12 +469,13 @@ static int h264_metadata_update_fragment(AVBSFContext *bsf, AVPacket *pkt, H264MetadataContext *ctx = bsf->priv_data; int err, i, has_sps, seek_point; - // If an AUD is present, it must be the first NAL unit. - if (au->nb_units && au->units[0].type == H264_NAL_AUD) { - if (ctx->aud == BSF_ELEMENT_REMOVE) - ff_cbs_delete_unit(au, 0); - } else { - if (pkt && ctx->aud == BSF_ELEMENT_INSERT) { + if (ctx->aud == BSF_ELEMENT_REMOVE) { + for (i = au->nb_units - 1; i >= 0; i--) { + if (au->units[i].type == H264_NAL_AUD) + ff_cbs_delete_unit(au, i); + } + } else if (ctx->aud == BSF_ELEMENT_INSERT) { + if (pkt) { err = h264_metadata_insert_aud(bsf, au); if (err < 0) return err;