From patchwork Mon Mar 4 17:32:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Gaullier X-Patchwork-Id: 46782 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d808:b0:19e:cdac:8cce with SMTP id iv8csp139283pzb; Mon, 4 Mar 2024 09:32:42 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUZ3Q3kKpkYmFF79el1MfKBe5ltuHiN9tIMiPsGk5vP14J9fgf79vL4BAA8ibGQutLAnWJQk6nr0n+KqzFArlApZms7w850wzWs+Q== X-Google-Smtp-Source: AGHT+IHKhtGXFcWYDM2pmggdt6vYH6baApykqyRl/0460Nv5/fy25OKlV4JUhYydnmqVcpAjyBbh X-Received: by 2002:a2e:9d86:0:b0:2d2:4b57:1c03 with SMTP id c6-20020a2e9d86000000b002d24b571c03mr5510556ljj.5.1709573562265; Mon, 04 Mar 2024 09:32:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709573562; cv=none; d=google.com; s=arc-20160816; b=L0JmzxcQDGfC1q4opwwyLvQNUf4d5TAc4ZhyhC4DL8FpTfTFTiMhb6mbcHXJPkPYzK fVY78i0PTYaW05eOYX7iUW6+hzL6M5AtBqnRDawrwSCuv/EUAsNK4XJA/Krb1ROlo8us xBlbPP3zKySwSFUVniuq4Lksm5dpC/lj28b9YwB2IAKtW35AbML6YZnxWz5dZeqlpn5/ JESKO5vKQY0cjRpjU8uChq5/5zN49/OgbO6SYUFDuhmQv/7M7+6H9p0yyvhrf30XcgKu U9VUZNBzyQexAzi07/X30SGOXMqloSWECfGjSk9Cikdr2JaHwJDhC2AtcBTaZwJjAagg OkJg== 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 :message-id:date:to:from:delivered-to; bh=+G/mQyyB40ki36C1AhlUcb88yZZPFN1yhXkJym7ryQY=; fh=zgMS+X4RExv2k7fU8QdWClnqVJdqO/9UbUuBS5xxJDs=; b=fE67B413pGjiDpjsskeSRbOn4tg7buWZMRSzAI0iCQKeGRXlgrmBkpeyzPqZ0z6L9Q 06+ltc64QPfrWMIfKx539d7N7j/TpU2dUOE23oV2VU8tL5cIoBorjGwtITkCXyRNPdZ0 r92PxYCrRP4yxDrvejx6jgOpBxy2E9QMGIIZ9YpiQ8NU+76ySzR6xEPCJ8qB8GliUuRN wvDy3nyag05bBXIjfYO5Tj6ZHJineZU800muiVcbvoxIdZo2jr+GSdvnANg8MypbAcRS OumNOUDcoHn7uSvdcsLKHgNbUeupgY8q3+8VCkmvaqzYQmwBnA8wMzmCxei98Cs/QlvU 3Hcw==; dara=google.com 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 x9-20020a05640226c900b00565dcc278fasi4036700edd.540.2024.03.04.09.32.35; Mon, 04 Mar 2024 09:32:42 -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 ED7A868D480; Mon, 4 Mar 2024 19:32:30 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from srv-infra-2.infra.inf.glb.tvvideoms.com (www.inf.tvvideoms.com [213.205.126.156]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4790368D417 for ; Mon, 4 Mar 2024 19:32:24 +0200 (EET) Received: from cji.paris (unknown [172.16.3.159]) by srv-infra-2.infra.inf.glb.tvvideoms.com (Postfix) with ESMTP id 8998041361; Mon, 4 Mar 2024 17:32:23 +0000 (UTC) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Mar 2024 18:32:18 +0100 Message-Id: <20240304173219.1877658-5-nicolas.gaullier@cji.paris> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240304173219.1877658-1-nicolas.gaullier@cji.paris> References: <20240304173219.1877658-1-nicolas.gaullier@cji.paris> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Nicolas Gaullier Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: rg/oRZdTTax2 Signed-off-by: Nicolas Gaullier --- 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 ||