From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTP id 54A5948F69
	for <ffmpegdev@gitmailbox.com>; Fri,  1 Mar 2024 13:40:14 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9742E68D284;
	Fri,  1 Mar 2024 15:39:37 +0200 (EET)
Received: from srv-infra-1.infra.inf.glb.tvvideoms.com (www.inf.tvvideoms.com
 [213.205.126.156])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9CD9068D256
 for <ffmpeg-devel@ffmpeg.org>; Fri,  1 Mar 2024 15:39:26 +0200 (EET)
Received: from cji.paris (unknown [172.16.3.159])
 by srv-infra-1.infra.inf.glb.tvvideoms.com (Postfix) with ESMTP id 242EE215EC; 
 Fri,  1 Mar 2024 13:39:26 +0000 (UTC)
From: Nicolas Gaullier <nicolas.gaullier@cji.paris>
To: ffmpeg-devel@ffmpeg.org
Date: Fri,  1 Mar 2024 14:39:22 +0100
Message-Id: <20240301133923.1132924-5-nicolas.gaullier@cji.paris>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20240301133923.1132924-1-nicolas.gaullier@cji.paris>
References: <20240301133923.1132924-1-nicolas.gaullier@cji.paris>
MIME-Version: 1.0
Subject: [FFmpeg-devel] [PATCH v2 4/5] avcodec/h264_parser: fix start of
 packet for some broken streams
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Cc: Nicolas Gaullier <nicolas.gaullier@cji.paris>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/20240301133923.1132924-5-nicolas.gaullier@cji.paris/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>

Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
---
 libavcodec/h264_parser.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index 94cfbc481e..6b721ec253 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -124,7 +124,16 @@ static int h264_find_frame_end(H264ParseContext *p, const uint8_t *buf,
             if (nalu_type == H264_NAL_SEI || nalu_type == H264_NAL_SPS ||
                 nalu_type == H264_NAL_PPS || nalu_type == H264_NAL_AUD) {
                 if (pc->frame_start_found) {
-                    i++;
+                    /* Some streams in the wild are missing the zero_byte at the NAL_AUD:
+                     * it is following just afterwards.
+                     * To avoid any accidental borrowing of a byte in the previous frame
+                     * (which would return a negative index and indicate that fetch_timestamps
+                     * has to get the pts from the previous frame),
+                     * better have the start of packet strictly aligned.
+                     * To make it a more general rule, just test the following three bytes are null.
+                     */
+                    i += 1 + (!p->is_avc && state == 5 && i == 3 && nalu_type == H264_NAL_AUD &&
+                        buf_size >= 9 && !AV_RB24(buf + 5));
                     goto found;
                 }
             } else if (nalu_type == H264_NAL_SLICE || nalu_type == H264_NAL_DPA ||
-- 
2.30.2

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