From patchwork Wed May 31 14:54:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41907 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3327143pzb; Wed, 31 May 2023 07:55:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7nibN0naNHDTx+EgODyZnwwLqWPwgHzAhvGhxPtDMWO8rAxS26XTaf5SWaSqx16s2V9xEO X-Received: by 2002:a17:907:7f8d:b0:96b:6fb:38d6 with SMTP id qk13-20020a1709077f8d00b0096b06fb38d6mr6074033ejc.65.1685544918484; Wed, 31 May 2023 07:55:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685544918; cv=none; d=google.com; s=arc-20160816; b=DLj1cGtJ4+/DsVa3WLmlXnlxPpQCm9XSpf8GuKtfMPhd8jAsf3BUS3RpwDuqjX1Qwp CbWBYZL3G9UBgDeBInKX28Gj9OmBDb46A8+hsVZZbrzGkCjAVPOObcyuTAH9oajjyLJj NkLA3uC91EpcY9jU4iSwFJNS/QmYDy9vcSpcOyG43K4c32GzhgDdt431x7cEr6Y9ddo5 MFnWmGazkq2w8WRrXNW1Laj6oh2IuT5YaUqQhfRR/XVtmpolZ+z+HhVLbel5ftb7KzPO JWyhbAA1TlUfPHHG1lVKq3veJJNBvFmEqW6TjMKF2jR1XV/Hm/Kw/RCNTokSBbkEo25d cN7Q== 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:references:in-reply-to:message-id :date:to:from:delivered-to; bh=GPtjv75PqUAEBkXPt8eiiKHnUBSnTxes6Q4EoeNkhmA=; b=tXk0mS+X3nhUe19pVbkHrvqG7tjA6BuProHOeHa4dWkz6bDIWTQjTsAHEjGpDJ9Whv fN8sMhyH6nuUMDjxNPLSrsI5k9fpIt7qI2taZVl+16SkS/YXTi2vYhdauYfQxGsop1JK Umf+hLBrSfK0PUExLcDq1LCs8IoXz48N+boJuClHzDXrjCGgJfZ0cY1NlgI7/8eTfb4j QAKSOJ10ZOjfxerlkP0og76lLl12wU96yNIx/nBiTKyrO8p80sOsQpNc4/7GRhar5f2L AtBXN4Qd8isOojTraoo8uKIuEeh49dDZ4hB51GNCNgwOTCGwF5IymNeR15qjfUHSDSyT tHRg== 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 qt20-20020a170906ecf400b0096b06ea4e84si5064264ejb.702.2023.05.31.07.55.17; Wed, 31 May 2023 07:55: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; 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 0C26868C260; Wed, 31 May 2023 17:55:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DCCB968B649 for ; Wed, 31 May 2023 17:55:06 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 1F0CE240706 for ; Wed, 31 May 2023 16:55:06 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id XSand4GjI_Au for ; Wed, 31 May 2023 16:55:05 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 6EA8E2404EC for ; Wed, 31 May 2023 16:55:05 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 0E10C3A058B for ; Wed, 31 May 2023 16:55:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:36 +0200 Message-Id: <20230531145453.20994-6-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/23] fftools/ffmpeg_enc: avoid breaking exactly integer timestamps in vsync code 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: unYcK5MhEUr3 The code will currently add a small offset to avoid exact midpoints, but this can cause inexact results when a float timestamp is exactly representable as an integer. Fixes off-by-one in the first frame duration in multiple FATE tests. --- fftools/ffmpeg_enc.c | 6 ++++-- tests/ref/fate/apng-osample | 2 +- tests/ref/fate/film-cvid | 2 +- tests/ref/fate/filter-concat-vfr | 2 +- tests/ref/fate/gif-gray | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index fab71ca0c0..d390e384ed 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -888,9 +888,11 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost, float_pts = av_rescale_q(frame->pts, filter_tb, tb) - av_rescale_q(start_time, AV_TIME_BASE_Q, tb); float_pts /= 1 << extra_bits; - // avoid exact midoints to reduce the chance of rounding differences, this + // when float_pts is not exactly an integer, + // avoid exact midpoints to reduce the chance of rounding differences, this // can be removed in case the fps code is changed to work with integers - float_pts += FFSIGN(float_pts) * 1.0 / (1<<17); + if (float_pts != llrint(float_pts)) + float_pts += FFSIGN(float_pts) * 1.0 / (1<<17); frame->pts = av_rescale_q(frame->pts, filter_tb, enc->time_base) - av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base); diff --git a/tests/ref/fate/apng-osample b/tests/ref/fate/apng-osample index c91dd5284d..6cf74a99ee 100644 --- a/tests/ref/fate/apng-osample +++ b/tests/ref/fate/apng-osample @@ -3,7 +3,7 @@ #codec_id 0: rawvideo #dimensions 0: 116x135 #sar 0: 0/1 -0, 0, 0, 2, 62640, 0x31eb581d +0, 0, 0, 3, 62640, 0x31eb581d 0, 3, 3, 3, 62640, 0x29e11b82 0, 6, 6, 3, 62640, 0x207ed588 0, 9, 9, 3, 62640, 0x3845c906 diff --git a/tests/ref/fate/film-cvid b/tests/ref/fate/film-cvid index 60bbc192d8..428cb6e9f0 100644 --- a/tests/ref/fate/film-cvid +++ b/tests/ref/fate/film-cvid @@ -3,7 +3,7 @@ #codec_id 0: rawvideo #dimensions 0: 320x224 #sar 0: 0/1 -0, 0, 0, 1, 215040, 0x067c5362 +0, 0, 0, 2, 215040, 0x067c5362 0, 2, 2, 2, 215040, 0xd9eacb98 0, 4, 4, 2, 215040, 0x3c8a4cbd 0, 6, 6, 2, 215040, 0xbdf996e1 diff --git a/tests/ref/fate/filter-concat-vfr b/tests/ref/fate/filter-concat-vfr index 66e9007da8..3d984a4968 100644 --- a/tests/ref/fate/filter-concat-vfr +++ b/tests/ref/fate/filter-concat-vfr @@ -8,7 +8,7 @@ #codec_id 1: pcm_s16le #sample_rate 1: 44100 #channel_layout_name 1: mono -0, 0, 0, 199999, 230400, 0x88c4d19a +0, 0, 0, 200000, 230400, 0x88c4d19a 1, 0, 0, 1024, 2048, 0xb3f10192 1, 1024, 1024, 1024, 2048, 0xb340fe4e 1, 2048, 2048, 1024, 2048, 0x0a5f0111 diff --git a/tests/ref/fate/gif-gray b/tests/ref/fate/gif-gray index aa3969212d..c246d8a670 100644 --- a/tests/ref/fate/gif-gray +++ b/tests/ref/fate/gif-gray @@ -3,7 +3,7 @@ #codec_id 0: rawvideo #dimensions 0: 480x360 #sar 0: 0/1 -0, 0, 0, 4, 691200, 0xef6c0f3d +0, 0, 0, 5, 691200, 0xef6c0f3d 0, 5, 5, 2, 691200, 0xc18b32de 0, 7, 7, 2, 691200, 0x2395a3d7 0, 9, 9, 2, 691200, 0x81dc3cf2