From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id D325A4C5E2 for ; Fri, 7 Feb 2025 15:24:23 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2DE1E68B796; Fri, 7 Feb 2025 17:24:20 +0200 (EET) Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 00CCA68B480 for ; Fri, 7 Feb 2025 17:24:12 +0200 (EET) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-21f44e7eae4so29323095ad.2 for ; Fri, 07 Feb 2025 07:24:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738941851; x=1739546651; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=ZhG64yPseeXJO31SPOes5OMSa8xxJafTww2VPrqtxig=; b=GH6i6gV2goKyeSyDPNH3JcasXQHjLIybzJwCtvEGk64NveMoJurY+g6FxD6FP44poY RLD+NS8lxlJXTkh2I7C7BJ3y0G6Z3cJBPpv5hxPeUY4Y8Z5UFmGkTmunJdYF6qgiq9xP 9MeuomCpL+4dX5Yj4ycyNmgcg7Q2ov+tE1HCQDpoCj6GEidV6SEAVJTjEhi1iXdAgxiT LIRqarN7WzbHvGze3ylMkwIxDjo2pOEr82wDkj6ZQj+dCPV/UDl9I63D3EIwF25U/9oe mqAJMrUx35f/UyhI+AYT7B9a0Vpbk3yyQMkdNhCJMlNijr3taTuYLjXlPgecFY5zNFqy lUcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738941851; x=1739546651; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZhG64yPseeXJO31SPOes5OMSa8xxJafTww2VPrqtxig=; b=cx/79aVrdbdfugki1VHaofKqodwBx7pgsfws6TS1GKmHoGoev1auK3ZlYV3nehT+6M 3flIh+ZDyGucapdwcajDU4DpMcGnL8zJg2s7ETZaDUHoqECng/m8aZB29HfrAr5is3th ZPAuUwdpW1q/hZziqH/7nRaZt4leuH8psv6b7xKUx9GCCT2F1s0cVl1erkw7+UZr8oQH k+H7jxVB/d9RSpdIgwNAZnBuB0jo/4WMvPV54E/6nNUhlkz9EJsuU7nWWCh5WWNPBHho V6v2Mddbn4WX6rs0iFAwhbwJTLhQKXFumetvphchslm8/gfNpIcDk8xRdNMf7bTdnWil C4/g== X-Gm-Message-State: AOJu0YyMy95JGo/IhZB13QonuRBuTngDwkz4/D5bjfKswlrWy0hb1sH4 35wsotBnOc1LuPdw2TyNQAhMsUcGsKMpvjDxtr7uksX6B4fpW5gSZaXYsew2 X-Gm-Gg: ASbGncvo111NwyPutA6zMIbMP3w2anCbVfh71DdOoJ+8c+Hg+z9R5pnWi2CKkYb7Ptt PSaunw1r7e4HN6Wx7XShSrgT9AYW2kaslIGlI8htHTBtgtcXvGl0t8tRF0zJs6d8BoDU5iMbNIU dBPntZezuVALSTdGYTnwHUqOo7j5gqiUF0NyvqD+9nmGcmgH1JD+ctEEPJ7lSmstmuXicOrA9DS wTYnKMo0d++FmWyKJ5AInCqvVsc9XUlSuM/oZPWNV2rC0tJ8Q7GIuQ+0hHbU06wtM4OLkvk1Diu GS3WB4ca2segfwqom1wgEJWPFfkWd7Dd X-Google-Smtp-Source: AGHT+IHCzFfaS/4Xz5WjeWJf3m0noXq+ZxgAElSSduiDDrRAGTQjjqATieX8tW/eNpi3HgkqDsoRrQ== X-Received: by 2002:a05:6a20:c707:b0:1e6:8f39:d635 with SMTP id adf61e73a8af0-1ee03a24244mr6650078637.9.1738941850455; Fri, 07 Feb 2025 07:24:10 -0800 (PST) Received: from localhost.localdomain ([2800:2121:b040:c:d1b4:52e7:1b9b:e89c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73048ac7095sm3133984b3a.39.2025.02.07.07.24.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Feb 2025 07:24:09 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Feb 2025 12:21:48 -0300 Message-ID: <20250207152149.518-1-jamrial@gmail.com> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/hevc_mp4toannexb: prepend extradata before the leading PS for an IRAP 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Parameter sets may be coded in the packet before an IRAP (as is the case for the hev1 ISO-BMFF brand), and they should have priority as they may override the extradata ones. As such, prepend the extradata PS NALUs to the packet PS NALUs if they are present before an IRAP, instead of prepending them to the IRAP slice. Should fix ticket #11458. Signed-off-by: James Almer --- libavcodec/bsf/hevc_mp4toannexb.c | 34 +++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/libavcodec/bsf/hevc_mp4toannexb.c b/libavcodec/bsf/hevc_mp4toannexb.c index f281185769..60f38ac414 100644 --- a/libavcodec/bsf/hevc_mp4toannexb.c +++ b/libavcodec/bsf/hevc_mp4toannexb.c @@ -126,6 +126,7 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) GetByteContext gb; int got_irap = 0; + int got_ps = 0, seen_irap_ps = 0; int i, ret = 0; ret = ff_bsf_get_packet(ctx, &in); @@ -140,10 +141,37 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) bytestream2_init(&gb, in->data, in->size); + while (!got_irap && bytestream2_get_bytes_left(&gb)) { + uint32_t nalu_size = 0; + int nalu_type; + + if (bytestream2_get_bytes_left(&gb) < s->length_size) { + ret = AVERROR_INVALIDDATA; + goto fail; + } + for (i = 0; i < s->length_size; i++) + nalu_size = (nalu_size << 8) | bytestream2_get_byte(&gb); + + if (nalu_size < 2 || nalu_size > bytestream2_get_bytes_left(&gb)) { + ret = AVERROR_INVALIDDATA; + goto fail; + } + + nalu_type = (bytestream2_peek_byte(&gb) >> 1) & 0x3f; + bytestream2_skip(&gb, nalu_size); + got_irap |= nalu_type >= HEVC_NAL_BLA_W_LP && + nalu_type <= HEVC_NAL_RSV_IRAP_VCL23; + got_ps |= nalu_type >= HEVC_NAL_VPS && nalu_type <= HEVC_NAL_PPS; + } + seen_irap_ps = got_irap && got_ps; + got_irap = got_ps = 0; + + bytestream2_init(&gb, in->data, in->size); + while (bytestream2_get_bytes_left(&gb)) { uint32_t nalu_size = 0; int nalu_type; - int is_irap, add_extradata, extra_size, prev_size; + int is_irap, is_ps, add_extradata, extra_size, prev_size; if (bytestream2_get_bytes_left(&gb) < s->length_size) { ret = AVERROR_INVALIDDATA; @@ -162,9 +190,11 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) /* prepend extradata to IRAP frames */ is_irap = nalu_type >= HEVC_NAL_BLA_W_LP && nalu_type <= HEVC_NAL_RSV_IRAP_VCL23; - add_extradata = is_irap && !got_irap; + is_ps = nalu_type >= HEVC_NAL_VPS && nalu_type <= HEVC_NAL_PPS && seen_irap_ps; + add_extradata = (is_ps || is_irap) && !got_ps && !got_irap; extra_size = add_extradata * ctx->par_out->extradata_size; got_irap |= is_irap; + got_ps |= is_ps; if (FFMIN(INT_MAX, SIZE_MAX) < 4ULL + nalu_size + extra_size) { ret = AVERROR_INVALIDDATA; -- 2.48.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".