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 7ED8242888 for ; Thu, 5 May 2022 23:05:12 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BB7FD68B367; Fri, 6 May 2022 02:05:09 +0300 (EEST) Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A5C71689FD9 for ; Fri, 6 May 2022 02:05:03 +0300 (EEST) Received: by mail-pl1-f169.google.com with SMTP id x18so5749593plg.6 for ; Thu, 05 May 2022 16:05:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=cAgkJBQBEL02B/MdAi9vEk7+4KJFNjuAOswUPRgcLd8=; b=no3ut2qbphDCD8a+S9pmXn2dsGDEfA815kGjoeLeOrCTVZp9728INi9A3vfJoPtSpf gJ2+wV+7MDsNA/Z4kJAM8IeGn90EUmhnGdLRO5q14kr+pDR1RUK+USJ8nN+ZAlSuxD78 Wx19jam98km1+A4despsSIFOu09ircxIHq85qwU7myJWbHQBhrxOwHKIwduNHxm3kqMp CCJ+AGKdVtW48D7nf9t10n/UTQURUo8LOPkaerykXdCJ5SNqD2ZO9a0F19V/qmUONdIR mnb8CBAghZbETmDfGeJrtqlUkRmw5525uo85pQWXryghmcEVc9etpVh8of5qmP7SkIkq 9VUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=cAgkJBQBEL02B/MdAi9vEk7+4KJFNjuAOswUPRgcLd8=; b=fMjtdnMTtXka6HTj3jzqpIi7uwuNPxu8pQSlkc4Yd3C24kmk+2+dstlw+zHor81PUE tdMZaRMFN+VB34ltTRjjnOvvjm8cESaCR75WgsAuDonEaeOtg4ujnapVA8bigWizBLCR ZZpuCAH4KQhqHiowlGBTLAp21Xr6en+bOAGHsmtNvzwKZV8v2azXHApADogRVRNHrvfs 82Y+SkjORx3hjTegITtgh731MFlMBc3/gsnMI9jQLaW3XUcZ/BqnxEQVjEYJhkKbRsLt Aug8zplTVpWSU7Id6UGb6pEt2p3J3UhyxWwM6dxRaR8BFhTYu/zXtvsMjkdUYh9C3gzp 4Btg== X-Gm-Message-State: AOAM532ym0uBSEbIJmIVBbN7LrHCaX5gqrE15JmCB7JV/vh/sTJl7s17 pirbmmGIh8Y+Pew1hlDPvnmY8vjO828= X-Google-Smtp-Source: ABdhPJxivtpCpIbd1GQb/8TA1QN2aMUjOHzzOSS0J1q5GahgNFCmGRbogVERLzT7rNaMtW93L1x/1Q== X-Received: by 2002:a17:902:f155:b0:15e:a5f8:e12a with SMTP id d21-20020a170902f15500b0015ea5f8e12amr562813plb.30.1651791901134; Thu, 05 May 2022 16:05:01 -0700 (PDT) Received: from localhost.localdomain ([23.173.192.144]) by smtp.gmail.com with ESMTPSA id f19-20020a17090a639300b001d840f4eee0sm5836103pjj.20.2022.05.05.16.04.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 May 2022 16:05:00 -0700 (PDT) From: Guangyu Sun X-Google-Original-From: Guangyu Sun To: ffmpeg-devel@ffmpeg.org Date: Thu, 5 May 2022 16:04:58 -0700 Message-Id: <20220505230458.1024-1-gsun@roblox.com> X-Mailer: git-send-email 2.30.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/oggparsevorbis: Fix oggvorbis duration parsing for small files 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 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: The decoded Data is not returned from the first frame; it must be used to 'prime' the decode engine. The duration of the first packet should be ignored also by the container, to make sure the total duration is trimmed correctly. If the file has multiple pages for the data packets. The duration of the last packet can be correctly adjusted without being affected by the first packet. But if the first packet and the last packet are located in the same page, the duration of the last packet will have an unwanted offset. This commit fixes https://trac.ffmpeg.org/ticket/6367. dd if=/dev/zero of=./silence.raw count=1 bs=500 oggenc --raw silence.raw --output=silence.ogg oggdec --raw --output silence.oggdec.raw silence.ogg ffmpeg -codec:a libvorbis -i silence.ogg -f s16le -codec:a pcm_s16le silence.libvorbis.ffmpeg.raw ffmpeg -i silence.ogg -f s16le -codec:a pcm_s16le silence.native.ffmpeg.raw ls -l *.raw Signed-off-by: Guangyu Sun --- libavformat/oggparsevorbis.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c index 289900f7cf..9a486c9fe8 100644 --- a/libavformat/oggparsevorbis.c +++ b/libavformat/oggparsevorbis.c @@ -412,6 +412,7 @@ static int vorbis_packet(AVFormatContext *s, int idx) struct ogg_stream *os = ogg->streams + idx; struct oggvorbis_private *priv = os->private; int duration, flags = 0; + int first_page; if (!priv->vp) return AVERROR_INVALIDDATA; @@ -420,7 +421,8 @@ static int vorbis_packet(AVFormatContext *s, int idx) * here we parse the duration of each packet in the first page and compare * the total duration to the page granule to find the encoder delay and * set the first timestamp */ - if ((!os->lastpts || os->lastpts == AV_NOPTS_VALUE) && !(os->flags & OGG_FLAG_EOS) && (int64_t)os->granule>=0) { + first_page = !os->lastpts || os->lastpts == AV_NOPTS_VALUE; + if (first_page && !(os->flags & OGG_FLAG_EOS) && (int64_t)os->granule>=0) { int seg, d; uint8_t *last_pkt = os->buf + os->pstart; uint8_t *next_pkt = last_pkt; @@ -479,6 +481,13 @@ static int vorbis_packet(AVFormatContext *s, int idx) flags = 0; } os->pduration = duration; + /* Data is not returned from the first frame; it must be used to 'prime' + * the decode engine. The duration of the first packet should be ignored + * also by the container, to make sure the total duration is trimmed + * correctly. + */ + if (first_page && os->segp == 1) + os->pduration = 0; } /* final packet handling -- 2.30.1 _______________________________________________ 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".