From patchwork Thu May 5 23:04:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guangyu Sun X-Patchwork-Id: 35608 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a885:b0:7f:4be2:bd17 with SMTP id ca5csp1354126pzb; Thu, 5 May 2022 16:05:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbYnH8U1AprPdlZf3z3KwriUGdIYcoPCsh6yGQeXLajKfZQ70Jo81tCbGYpdzr268VMapt X-Received: by 2002:a17:906:7954:b0:6f4:dfbf:2bad with SMTP id l20-20020a170906795400b006f4dfbf2badmr422146ejo.141.1651791914207; Thu, 05 May 2022 16:05:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651791914; cv=none; d=google.com; s=arc-20160816; b=jbtxCYggZBCTP/NpqsOfSgxRBAq3guNiT/nYMeq8eEsbxYfcYDFEXV0iS/QSu8J7PW LwekUXuTD2tqorrXLCTugVmZmuWdPIuKwx7qkl4aFRuV1EH2rLqqrKESftpy/ILIi9Z9 YDpBQ2unwFjjGhSsQ31FY0c14eBthW1fubIUrC2H0+g0KN9Tgswt9/GO3cOSoLBGKyGQ SNDmsVs+sfgMOQcE/6m6agr8ahqEmq2LWOB6oy31AI4fuOztRXOT64H1HFgBIGBby+GN McSTz6vcjuGtrHPfxrLfYnrqg0lP8GaLlK2TtsWQWDTXYmNv4OSxaijwc6Ia/iZCJdyy MflQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=Dz6s4AJGMd23tKcFYcPb/XVCznCJ3gft1BxnLmxFB+c=; b=NTgrfIf0oEiJwpmsyTVNmtzO/oJrMLZmh7LnlrOMFReI5QSZ6bR2+Ydo8YMMxW7cwA 1p4ZW8zcBF+PYYXI+ZoRUCpKa7eI1nKwxNreb1c6iJ1zJ5fuhrCT6s5u6nF4zGrwUDjz iEjk2z8dZOgmS2ZUd9gvc2pEH3PRbXzNXQ3H487Sg6bFTU2CsSVZKW/MrJp0zzb5eBck 4aCdpCd0kUH3hJ5rhEk3rRCJwDkZOMi209KxQ8O+mftRvfD/3dNUvAZERQdqmVBNsWgi ztki269bLRa83WvLBfwgxZ5OYMN3hxbm1YVvM44+IOFqVRt6ntYrhrXfamZMN4UV56ZT 4+hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=no3ut2qb; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id wh24-20020a170906fd1800b006e87d13d583si3229746ejb.248.2022.05.05.16.05.13; Thu, 05 May 2022 16:05:14 -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=@gmail.com header.s=20210112 header.b=no3ut2qb; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F36D7689FD9; Fri, 6 May 2022 02:05:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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-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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 45fF587ma22L 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