From patchwork Mon Jun 21 16:05:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guangyu Sun X-Patchwork-Id: 28591 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2042:0:0:0:0 with SMTP id z2csp2105511iod; Mon, 21 Jun 2021 09:06:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOUTP/HtFq3vq8tPltsatKX/biqbBDYuuE9CRvHyhDi7Gn3PojbrkYlW9kbuKYHck6AdMz X-Received: by 2002:a05:6402:2898:: with SMTP id eg24mr12016092edb.155.1624291617070; Mon, 21 Jun 2021 09:06:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624291617; cv=none; d=google.com; s=arc-20160816; b=BhFUrVyp2KV69uqQG7xZib/ZM1dgtdoVOpS2JVTIhy9xCMKAr/SeM7t35YYRKTUvaD v8TwbGX+VqfdcT7JNe4zutwdxUsuVWH0oQ8d66jrgShtZfq8VggpR9fCo8d/GuikWH/9 E0tLer3ouh0SnpMHokYVEbWhGASY3CPWmG0MuEFfDgKlDHAKAl4kIzncSeS2++QF5l+b Z4gwDO0W/HEdswLIUT6M8lX3RdoAj6gv4r7B0RwaPrJMThVmJJBIiOMDWMLyDv94fAe4 FV9FA/bU4AQMoZfZSFXfUMLYVGi+yCXoqqr53yqd0YO5L98+wfZe7yi7rWQ0znXHb1cH jZkw== 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 :dkim-signature:delivered-to; bh=etAfWGxzkenHLWdOhyB5doc8vODjsynJGwGBABj0A4Y=; b=AFTQ+CeV7m5M44VYFEvZJJyml1epQCXOlFGEI1RYp4z89FfkT1dDKAPGMU7xV/5mYF kRT57XUOb1STP6/QjBstkCjcBTpj5W9/r0MmUzrEggNCiExBp8kMmzgHg1JZx60FTv4r N8mgOdylcKbrSVh87zBvnpfg32MYRjti+smOj/nS+5iH+s3T5UIcetVNSP5rsIdr+/Uq hMuPAADel2s13eawwOlfor++QiSJbFtykp7QRUuVDpPIWLHldT0zC16rLJMq5jtk6YGA LMLmJZ2aRuxYxImU6ESw+Qhpfbox0GlJRVXxxpA5pOHn22dPmSSu335/DAmlasxRBoRI jgAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=b4LkDQFq; 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 gz21si4421433ejc.507.2021.06.21.09.06.56; Mon, 21 Jun 2021 09:06:57 -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=20161025 header.b=b4LkDQFq; 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 29AA1689E93; Mon, 21 Jun 2021 19:06:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 787AD689A1C for ; Mon, 21 Jun 2021 19:06:45 +0300 (EEST) Received: by mail-qt1-f182.google.com with SMTP id x21so4624017qtq.9 for ; Mon, 21 Jun 2021 09:06:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=H0HYvlcUsk9hwDOglrf6wNt3f3vp5GSqT+ypsFkRmRo=; b=b4LkDQFqVePvpaZOuNe5nHuqYzxbsw76ErxOux4bZJ2TJNkWNAdsnOVnc+CJ+7WgPu 0Em2esJu01QLdZUsJpHgb1s+SGv1DO/WUeu5NHmjrCwr1iXT82zgknr47nFWtTY0j9C3 YAZ3yQmjBE/Le1354ZCvwUxduJt3nII4xZ5+q2GaldRD7s9q+AFd7dDRZgnZXvHD7dtK A+FxOwcpK1Me8WnN8YvJW3SBl//mJCJQqdXU7Rwfu/9nxTU3XKrAHHTqSkqZ/sXS8kmX Br+HmAqhpqznhRkW0OvULqMQ8DJ+Arx7e0WxuwdWFBn+XMahMalCtkd4vg3zlpGW0nf9 5UxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=H0HYvlcUsk9hwDOglrf6wNt3f3vp5GSqT+ypsFkRmRo=; b=tX2RWNCh3YT6+VjVOOfrnc4WIN+qEllORyfwSbjPR0TCYncAq8YwUujgacZ/tsTy5f /oNwgY8beNz6Ha2kz4yMOLdZvqy2OvvBvziPnlV2v/X5bXencbw5c+sxe2SaVeMYgI1U FX1tv3Na19I8dWzNOaFyAINQyON8F/RC+PIP8Hm7nyjzP7WPYKtyVj8waUMbp/x/Z8wG Jtmxhfjy6Lgkk84oPLE8b801HP/JzxVg9k3QRPEdWcK+IK9r99ekOb4Dg5xtr2Fnv81u mMh+0WEArild3KRufFU4vsOKPLj70JTQUNoVywZl6Tw5eKsC9cZnd4rgP61FXn2hWjwZ Y4Jw== X-Gm-Message-State: AOAM53112E6I03e+onAVmzS0yINg4nrZ8E9LMYA1+L3n+G2POjg+Yk2M zhSZjVJSPLXVNFz8ddGkPZQWIEIr94SE/A== X-Received: by 2002:ac8:760e:: with SMTP id t14mr23677933qtq.240.1624291603970; Mon, 21 Jun 2021 09:06:43 -0700 (PDT) Received: from localhost.localdomain ([98.42.211.210]) by smtp.gmail.com with ESMTPSA id f193sm10108271qke.43.2021.06.21.09.06.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jun 2021 09:06:43 -0700 (PDT) From: Guangyu Sun X-Google-Original-From: Guangyu Sun To: ffmpeg-devel@ffmpeg.org Date: Mon, 21 Jun 2021 09:05:35 -0700 Message-Id: <20210621160535.71659-1-gsun@roblox.com> X-Mailer: git-send-email 2.30.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/oggparsevorbis: Update end_trimming for the last packet 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: Guangyu Sun Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: JN8/ohbN2nvT From: Guangyu Sun Without end_trimming, the last packet will contain unexpected samples used for padding. This commit partially fixes #6367 when the audio length is long enough. dd if=/dev/zero of=./silence.raw count=20 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 The original test case in #6367 is still not fixed due to a remaining issue. The remaining issue is that ogg_stream->private is not kept during ogg_save()/ogg_restore(). Field final_duration in the private data is important to calculate end_trimming. Some common operations such as avformat_open_input() and avformat_find_stream_info() before reading packet will trigger ogg_save() and ogg_restore(). Luckily, final_duration will not get updated until the last ogg page. The save/restore mentioned above will not change final_duration most of the time. But if the audio length is short, those reads may be performed on the last ogg page, causing trouble keeping the correct value of final_duration. We probably need a more complicated patch to address this issue. Signed-off-by: Guangyu Sun --- libavformat/oggparsevorbis.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c index 0e8c25c030..c48658ceda 100644 --- a/libavformat/oggparsevorbis.c +++ b/libavformat/oggparsevorbis.c @@ -492,8 +492,12 @@ static int vorbis_packet(AVFormatContext *s, int idx) priv->final_pts = os->lastpts; priv->final_duration = 0; } - if (os->segp == os->nsegs) + if (os->segp == os->nsegs) { + int64_t skip = priv->final_pts + priv->final_duration + os->pduration - os->granule; + if (skip > 0) + os->end_trimming = skip; os->pduration = os->granule - priv->final_pts - priv->final_duration; + } priv->final_duration += os->pduration; }