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 ESMTP id 137BA4707C for ; Fri, 23 Feb 2024 11:54:08 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7B37A68C5BF; Fri, 23 Feb 2024 13:54:05 +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 BA2ED68C462 for ; Fri, 23 Feb 2024 13:53:58 +0200 (EET) Received: from cji.paris (unknown [172.16.3.159]) by srv-infra-1.infra.inf.glb.tvvideoms.com (Postfix) with ESMTP id 7037E2070B; Fri, 23 Feb 2024 11:53:56 +0000 (UTC) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Fri, 23 Feb 2024 12:53:54 +0100 Message-Id: <20240223115354.367881-1-nicolas.gaullier@cji.paris> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Nicolas Gaullier 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: --- 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".