summaryrefslogtreecommitdiff
path: root/fftools/ffmpeg_enc.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2023-05-28 16:22:58 +0200
committerAnton Khirnov <anton@khirnov.net>2023-06-05 16:15:04 +0200
commitccf219e361957eef8fab45ce8b02cdf4d42e5e28 (patch)
tree046bc81e14869a524392bc7eecca2702b857e082 /fftools/ffmpeg_enc.c
parentc7a05ac117bc4152b27aa6127d67cb5bc0f09271 (diff)
fftools/ffmpeg_enc: avoid breaking exactly integer timestamps in vsync code
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.
Diffstat (limited to 'fftools/ffmpeg_enc.c')
-rw-r--r--fftools/ffmpeg_enc.c6
1 files changed, 4 insertions, 2 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);