From: Anton Khirnov <anton@khirnov.net> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 06/23] fftools/ffmpeg_enc: avoid breaking exactly integer timestamps in vsync code Date: Wed, 31 May 2023 16:54:36 +0200 Message-ID: <20230531145453.20994-6-anton@khirnov.net> (raw) In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> 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 -- 2.40.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".
next prev parent reply other threads:[~2023-05-31 14:55 UTC|newest] Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov 2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 02/23] fftools/ffmpeg_mux: set stream duration after the timebase is certainly known Anton Khirnov 2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 03/23] fftools/ffmpeg_filter: drop a write-only variable Anton Khirnov 2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 04/23] fftools/ffmpeg_filter: drop a block disabled since 2012 Anton Khirnov 2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 05/23] fftools/ffmpeg_demux: do not set AVCodecContext.framerate Anton Khirnov 2023-05-31 14:54 ` Anton Khirnov [this message] 2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 07/23] fftools/ffmpeg_mux_init: do not overwrite OutputStream.frame_rate for streamcopy Anton Khirnov 2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 08/23] fftools/ffmpeg_enc: merge two adjacent video-specific blocks Anton Khirnov 2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 09/23] fftools/ffmpeg_mux_init: only process -enc_time_base if the stream is encoded Anton Khirnov 2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 10/23] fftools/ffmpeg: handle -enc_time_base -1 during stream creation Anton Khirnov 2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 11/23] fftools/ffmpeg_enc: inline init_encoder_time_base() into its callers Anton Khirnov 2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 12/23] fftools/ffmpeg_enc: do not guess frame durations from output framerate Anton Khirnov 2023-05-31 15:16 ` Paul B Mahol 2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 13/23] fftools/ffmpeg_mux_init: do not overwrite OutputStream.frame_rate for encoding Anton Khirnov 2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 14/23] fftools/ffmpeg: convert timestamps inside the muxer Anton Khirnov 2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 15/23] fftools/ffmpeg: factor out attaching FrameData to a frame Anton Khirnov 2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 16/23] fftools/ffmpeg: attach filter framerate to frames Anton Khirnov 2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 17/23] fftools/ffmpeg_enc: stop using OutputStream.initialized Anton Khirnov 2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 18/23] fftools/ffmpeg: simplify handling input -t for streamcopy Anton Khirnov 2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 19/23] fftools/ffmpeg: stop explicitly closing output streams on input EOF Anton Khirnov 2023-05-31 21:15 ` Michael Niedermayer 2023-06-03 20:09 ` Anton Khirnov 2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 20/23] fftools/ffmpeg_mux: use a dedicated packet for BSF output Anton Khirnov 2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 21/23] fftools/ffmpeg_mux: simplify calling of_output_packet() Anton Khirnov 2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 22/23] fftools/ffmpeg_enc: use a private AVPacket instance for encoding Anton Khirnov 2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 23/23] fftools/ffmpeg_mux: make OutputStream.pkt private Anton Khirnov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230531145453.20994-6-anton@khirnov.net \ --to=anton@khirnov.net \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git