From patchwork Fri Mar 1 13:39: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: 35068 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a919:b0:19e:cdac:8cce with SMTP id cd25csp1268733pzb; Fri, 1 Mar 2024 05:39:49 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWSX79+h/7B09y0AW7U2AfnEGUJ35+Pyn7GlGWo0HG+ALgiuk2vixitFZsUihStQRwJcsleuGBTEvLa8SIKCxQWIeDhsbJDnu4JuA== X-Google-Smtp-Source: AGHT+IHo28e4vBBwdhxLUWDf7fB+t3btSQe6S0BvqFUDhmi1KM3J3Rf5rND3IBeOLgrNye4JnNRO X-Received: by 2002:a17:906:ae4e:b0:a3e:473d:e391 with SMTP id lf14-20020a170906ae4e00b00a3e473de391mr1350416ejb.22.1709300389083; Fri, 01 Mar 2024 05:39:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709300389; cv=none; d=google.com; s=arc-20160816; b=JeaUUocjDESqXmVoomRRjp84rENvXHR3+n9XWYwW0W061uLlaG9yD311OpPQgtHHTD l484vBwRPu6lhvWKIKfM2FDJ2ucVuLIIyHekVYlPG3QAcXT9V4dDTR/SCFUBOz/XbmMM gFRYUtR8HcqVbUHKm2GpF25H0yzzMxqaxNrbgn2S2TKpN3dRGAcZx0VHrWgxxygxm22W uFm6m7TjgG9MffDfX/AIrgYpkEXAmLDSyyJItTqZtI1Gz7/lHhGey6CvwJqsfacbaCrm G+JIs0fUS4Jk5O09JX3uA5hooeUVGXi0fv0o9lqdQv5LouGRw/w7PE48V/82a/uywvlu R52g== 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:message-id:date:to:from :delivered-to; bh=8rXLNYIjLSGlfWFlXeckJHC2hXxTMlh4GN1lUMOdI0g=; fh=zgMS+X4RExv2k7fU8QdWClnqVJdqO/9UbUuBS5xxJDs=; b=pSIQrmlaw0FDUvHVW5WT2S52M8nOW1u00+yyr/EhIO9O3D7qo5eMUXn8zSy8NUSBw/ LkhUdLd0atFnDrVvcRG9I/jHValQvNmojgFzlmtN3g1zwE1JZlPZjdWnCqhv/DjkYDIZ xZ1TA68+oqkVs7xdNBw/EhAdHWkCs0sIZfLwc+4VjFWQDVM9k3ON7V4dDllyc9yOBeeU D8mDN1epletM2ds9K0XDIBTH+1eWjxb0lFoEGPrfTOHyDEOKPl3dusDM6tzLE9IkF7I+ nqMzgxxJp+HIgJTuFBw3o6HDEGZMvIowgTZvXDax4Ia4rYWSGPLAt+fjszlYKd9Rod6N CMuA==; 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 c6-20020a170906694600b00a441dd88f3fsi1439620ejs.320.2024.03.01.05.39.48; Fri, 01 Mar 2024 05:39:49 -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 B38F668D0AF; Fri, 1 Mar 2024 15:39:34 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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 9611568D1A8 for ; 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 976D41FF26; Fri, 1 Mar 2024 13:39:25 +0000 (UTC) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Fri, 1 Mar 2024 14:39:18 +0100 Message-Id: <20240301133923.1132924-1-nicolas.gaullier@cji.paris> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 0/5] avcodec/parser: fix fetch_timestamp in a scenario with unaligned packets 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: HwD9hiVn69ZW This is the following of https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=10843 The file submited by Michael highlighted 3 different and independent issues I missed in the first version: - some corrupt mpegts files are missing the zero_byte at the NAL, but a "full" NAL start including the zero_byte can be found just afterwards, so they can be identified. In some cases, there might be a terminal null byte at the end of the previous frame and thus it is "borrowed" by current code to form a complete, full NAL start: in such a case, the fix fetch_timestamp now get the pts of the previous pes, which is not expected. So, I've added a h264_parser patch (new patch 4) - the index may be negative even for the very first packet, despite pointing to no data, so I've added the "!s->frame_offset" condition to enable the "fetch timestamp in the past" patch - the mpegts demuxer has a "split packets" logic according to its max_packet_size, and in my understanding, the behavious of the current code does not look good, the cur_frame_arrays are fed with kind of "empty entries", which now raises an issue because some "past entries" are required to get proper timestamps from the previous frame, so this had to be fixed (new patch 1) : the entries of the splited packets should be merged to get consistent entries Patch 3: I forced the AVCodecParserContext offset to be positive. Patch 5: unchanged. Still not sure whether this patch is somewhat "required", "useless", or "bad". What possibly remains: as seen with some h264 broken streams in the wild, there might be other broken stream issues (hevc?). If such issues currently exists (but currently with no serious effect), there would be a regression in the PTS/DTS values. So any testing with corrupt streams beyond h264 is wellcome to see if other parsers require a fix (say a hack). For remembering, sample files and cover letter of the first version: https://ffmpeg.org/pipermail/ffmpeg-devel/2024-February/321819.html Nicolas Gaullier (5): avcodec/parser: merge packets from the same frame avcodec/parser: reindent after previous commit avcodec/parser: fix fetch_timestamp in a scenario with unaligned packets avcodec/h264_parser: fix start of packet for some broken streams lavf/demux: duplicate side_data in parse_packet() libavcodec/h264_parser.c | 11 +- libavcodec/parser.c | 29 ++-- libavformat/demux.c | 23 ++- tests/ref/fate/concat-demuxer-simple2-lavf-ts | 164 +++++++++--------- tests/ref/fate/ts-demux | 8 +- 5 files changed, 131 insertions(+), 104 deletions(-)