From patchwork Tue Feb 20 16:33:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Gaullier X-Patchwork-Id: 35063 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dda5:b0:19e:cdac:8cce with SMTP id kw37csp1965581pzb; Tue, 20 Feb 2024 08:33:26 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCULEhF8e4wpoqf658Wsh/JdA3aPFNnWda4Gc01c8JjptTroiMIiCkynMtlazSqrexUHPSRlEx6q6x3ZDXPj94rJ+n42kr9mrKNPDw== X-Google-Smtp-Source: AGHT+IGooNypZQWTMz/PfyD0bXaOiuQwp6fGjMfP5PWpYsfq6h/DztL5kKTUpFu+1Pa3mKST7ny6 X-Received: by 2002:a50:ee14:0:b0:564:a4e9:3688 with SMTP id g20-20020a50ee14000000b00564a4e93688mr2986440eds.10.1708446806470; Tue, 20 Feb 2024 08:33:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708446806; cv=none; d=google.com; s=arc-20160816; b=OVV55XMD2lY/wVoG+zCOF142DNa13LJtWlqlN/obUgvFY10RifXI1tqgeHWKki4oJ8 fwoVH6HUnRRKTjveFzbAN4D7gEOAxUD0PczKTjbTmjFa7h0cDep+W5yIQ6Lj5i7KgPRN ozPjVw/Civ+Fb9dfBlLMXvZjadH2cMvKGKHRrFRmvp1iMPdpbsxPkXafWVnWDewaS7nG H2pcAhh0zTEwRPKNZqOdy8N49DtTO+fi6WGp1GRskjtmp80p7QgOZzbHd/OlXfu0wNzh S551QPhKUrh2MIcgZnAYee4+vDQVBDUsFvMWhWXxBO7qH822sPF1DmNPkUJ01r8Y9//r DRrw== 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=gjuTORnPsWt3yKnRN62cKozqNunCruPcRVHLXHCZo6w=; fh=zgMS+X4RExv2k7fU8QdWClnqVJdqO/9UbUuBS5xxJDs=; b=jvqYsir5S3yaOYGcHk54S58PTfmmHVV4nfJivUWhkytFYrJPpkIEl2ApdPRGzXY4XI y/rcuz0eY3lWu9Jv+SJJRxDpQy/aVdDG4n13qHw44OUIwRAm8/7LM3a83ArPfhp04Ckj w5W9dGiyR7apwavendHLUzWow5kvU1tSrcv9ONQU/WKS4bRepd5xAoH8yz1Iz81RUFNx uNhiP6tQhdZdbjjoG9vS8519Axa15v1pYxIH1HKjsV1eqA3KYFdsVx8bA0lUELPnHv4Y Fh8RcjRWsSFE7IE8ak4TVWkQoingMzDIueb0d72b1FT34LWY5fv6kMuUz4XH4feGdeGr UoGA==; 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 l2-20020a50d6c2000000b0056459dad586si2498481edj.357.2024.02.20.08.33.26; Tue, 20 Feb 2024 08:33:26 -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 5D7EB68D252; Tue, 20 Feb 2024 18:33:13 +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 771B168C291 for ; Tue, 20 Feb 2024 18:33:06 +0200 (EET) Received: from cji.paris (unknown [172.16.3.159]) by srv-infra-1.infra.inf.glb.tvvideoms.com (Postfix) with ESMTP id 5F67720742; Tue, 20 Feb 2024 16:33:05 +0000 (UTC) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Tue, 20 Feb 2024 17:33:00 +0100 Message-Id: <20240220163302.1943993-1-nicolas.gaullier@cji.paris> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 0/2] fix an mpegts scenario with unaligned pes 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: E5Fa38K47PXC This is the scenario: - unaligned PES and NAL encoding - the first NAL of the access unit begins at the very end of a ts packet, sometimes only the 0x00 of the trailing byte (unfortunately, this is still conformant to the standards!) - the video frame is so small (ex: typically still picture) it fits in a ts packet and a new PES is immediately started Two sample files can be found here: a) https://0x0.st/HDwD.ts b) https://0x0.st/HDwd.ts For sample a, the first NAL (AUD) is splited this way: 0x00 / 0x00 0x00 0x01 0x09 And for sample b: 0x00 0x00 0x00 / 0x01 0x09 ffmpeg -i input.ts -f null /dev/null => Application provided invalid, non monotonically increasing dts... The parser can usually deal with unaligned packets thanks to the parser state, but here a new PES starts just right after the split and fetch_timestamp() does not know that the start of the PES was on the previous frame. An alternative straightforward fix directly in the mpegts demuxer is possible but really ugly, see: https://pastebin.com/J286CXDr I hope this proposal is looking better. It consists in two patches to get an identical output. The first patch fixes the fetch_timestamp mechanism. The second patch is to make parse_packet duplicate the side_data when spliting packets. It is not clear to me if this is required nor correct in a general manner? Nicolas Gaullier (2): avcodec/parser: fix fetch_timestamp in a scenario with unaligned packets lavf/demux: duplicate side_data in parse_packet() libavcodec/parser.c | 6 +- libavformat/demux.c | 23 ++- tests/ref/fate/concat-demuxer-simple2-lavf-ts | 164 +++++++++--------- tests/ref/fate/ts-demux | 8 +- 4 files changed, 107 insertions(+), 94 deletions(-)