From patchwork Mon Oct 30 18:56:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 44443 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4924:b0:15d:8365:d4b8 with SMTP id ft36csp9576pzb; Mon, 30 Oct 2023 11:57:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHsVqFXbFsGTBd7OwzC5KHhFiAdF7btqzSTpfn1+ID/+v4ioOiMvVH07QbCU7M7fMRVEuto X-Received: by 2002:a17:907:26c9:b0:9c7:6fa7:586e with SMTP id bp9-20020a17090726c900b009c76fa7586emr9873049ejc.1.1698692238459; Mon, 30 Oct 2023 11:57:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698692238; cv=none; d=google.com; s=arc-20160816; b=ctH31bmVNBf76P9ubAnQP/3T1pIVcP0+Kh6BkX0tKIZGNz1UQMWflxmSrBwb0MVcFG Ki+eRi7qaV76Z9ny4zfMTr2uvCtEXlurYz+u1ty/a2G/dKMt90VaKTwMYARPjas1B0Ec 3icfqL3lLaU66p45hr9LOHYARB1n1HB7rpJJKYMSBKaXgUBIFpPGDIkpFzO8hnT5Wddg nfOVPu+66ZdAIObNoYFx2NVfEsO0W3hQqiWskFwx9ZUcjXUpwsHmPoIqt9o+T5px3uFg zZrAWtCicWi/BfXa/FOG16vPWP80OorTmxNVRbT4RqNbflmBsTYRAQ5IQFp5wuZj+Swl 8g5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:message-id:to:from:date:dkim-signature:delivered-to; bh=u60zlUA7Mry7RjsPSLAmJdiC6PIW6iEv7CJ0fRMX7OI=; fh=Q46kXK7oI5D1Jhi90JBr53c7NIaTxGaU4KPeRZyM/hI=; b=TbPh5Ya7drUHvTZkhBFyuR6vMM5ICLz01/C6KUfnRKuRRodY/Q04rMI2QQ9VeVMpjW w4ItXlFYLxazyYvZohbUJlNoyvK90miW7k1vY9KinYuUBjV3JSpW4i0/3iAPkxryiQMZ NVv/jOXwTzwRoN5gdga7GDrmfhyJVs/S8Go+g/+9I1SdjnFEv2DOb2Jwx4eeIHaqe88z ANTHDVylujh8f3/M2LttRHavImbQQ4+YyjHD42rx+E0nd+94jbcSXp+/vJ/DQ0iCF6F+ SJ32nJKO+Ts2lExm3IebTOlli9I8ocIGqO/lhhhFsSh7Js1aP/eYM/Fs1kLQKRq8/xmW hqJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=w8JX8s7V; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=lynne.ee Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id hq12-20020a1709073f0c00b00991f598188csi2583612ejc.214.2023.10.30.11.57.11; Mon, 30 Oct 2023 11:57:18 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=w8JX8s7V; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=lynne.ee Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7040B68CCB6; Mon, 30 Oct 2023 20:57:07 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from w4.tutanota.de (w4.tutanota.de [81.3.6.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6973468C92B for ; Mon, 30 Oct 2023 20:57:00 +0200 (EET) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id 124AC1060307 for ; Mon, 30 Oct 2023 18:57:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1698692219; s=s1; d=lynne.ee; h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Cc:Date:Date:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:Sender; bh=E7O/1lV01JzRZEnKHpKwRfqbivd2NK92nq07RPVQ48w=; b=w8JX8s7Vn8HMBUc+rjc2H5wbdF3RoMlAVMv7IBuik+g6KygysDuULT1pTEE7fw6P pYgThfZW+FR12ZEbjrs6x27H2o2UuXXiYrprk4Pu5nTV4Nx1msgmtEdthfitDhB35Od sZEY4Z/Aw3+OgHABObLcDxYi/oAUN4D4FY/XjONDJ89e9m4DToVb4kd0HWr0NeiFnjl 3gyHMwcPm8QrGzEPEBE+YuAK6SyRU7oO25WeK+OyIlAkW2uyGLCJKz+EQ3A95MqeY17 0iwKwODAJ3PUxntrWjTD+diftynOp3WIxpq/DW7eys3ftPfsZmKDY0CF5vUKEhLk/VX 94hy9Yvptg== Date: Mon, 30 Oct 2023 19:56:59 +0100 (CET) From: Lynne To: Ffmpeg Devel Message-ID: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat: add AVFMT_INIT_ZERO_SKIP flag and use it in MOV 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Bzy9yfChOdKZ Meant to be applied on top my AAC patchset. MOV trims both the decoder/codec's algorithmic delay, and additionally, any samples the encoder needs removed, via edit lists, which we export as skip_samples side data. The issue is that if there are no edit lists, with the recent AAC decoding algorithmic delay removal patch, the default, algorithmic delay will be removed of 1024 samples. However, MOV specifies that this delay should be left as-is, even if edit lists are not used. demux.c, however, only signals a SKIP_SAMPLES side data if it is non-zero. Hence, this patch just changes this such that side data will always be put for MOV, even if it is zero, for only the first frame. This way, the decoder will not skip the algorithmic delay by itself. Patch attached. From 27e7e32e862b7dcd0f3c89a138f9ff64ed5042ed Mon Sep 17 00:00:00 2001 From: Lynne Date: Mon, 30 Oct 2023 19:42:14 +0100 Subject: [PATCH] avformat: add AVFMT_INIT_ZERO_SKIP flag and use it in MOV MOV trims both the decoder/codec's algorithmic delay, and additionally, any samples the encoder needs removed, via edit lists, which we export as skip_samples side data. The issue is that if there are no edit lists, with the recent AAC decoding algorithmic delay removal patch, the default, algorithmic delay will be removed of 1024 samples. However, MOV specifies that this delay should be left as-is, even if edit lists are not used. demux.c, however, only signals a SKIP_SAMPLES side data if it is non-zero. Hence, this patch just changes this such that side data will always be put for MOV, even if it is zero, for only the first frame. --- libavformat/avformat.h | 4 ++++ libavformat/demux.c | 3 ++- libavformat/mov.c | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 9e7eca007e..8a1ae91042 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -501,6 +501,10 @@ typedef struct AVProbeData { AVFormatContext.avoid_negative_ts */ +#define AVFMT_INIT_ZERO_SKIP 0x80000 /**< Format requires that skip_samples should + always be signalled, even if it is zero, + for the first frame. */ + #define AVFMT_SEEK_TO_PTS 0x4000000 /**< Seeking is based on PTS */ /** diff --git a/libavformat/demux.c b/libavformat/demux.c index 6f640b92b1..a4953d36f1 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -1398,7 +1398,8 @@ FF_ENABLE_DEPRECATION_WARNINGS if (sti->start_skip_samples && (pkt->pts == 0 || pkt->pts == RELATIVE_TS_BASE)) sti->skip_samples = sti->start_skip_samples; sti->skip_samples = FFMAX(0, sti->skip_samples); - if (sti->skip_samples || discard_padding) { + if (sti->skip_samples || discard_padding || + ((s->iformat->flags & AVFMT_INIT_ZERO_SKIP) && (pkt->pts == 0 || pkt->pts == RELATIVE_TS_BASE))) { uint8_t *p = av_packet_new_side_data(pkt, AV_PKT_DATA_SKIP_SAMPLES, 10); if (p) { AV_WL32(p, sti->skip_samples); diff --git a/libavformat/mov.c b/libavformat/mov.c index 2f29487beb..e012bd0291 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -9327,5 +9327,5 @@ const AVInputFormat ff_mov_demuxer = { .read_packet = mov_read_packet, .read_close = mov_read_close, .read_seek = mov_read_seek, - .flags = AVFMT_NO_BYTE_SEEK | AVFMT_SEEK_TO_PTS | AVFMT_SHOW_IDS, + .flags = AVFMT_NO_BYTE_SEEK | AVFMT_SEEK_TO_PTS | AVFMT_SHOW_IDS | AVFMT_INIT_ZERO_SKIP, }; -- 2.42.0