From 4aaa83339ca9515113e936af79bc3d860d67cb4b Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 19 Aug 2016 14:11:32 +0200 Subject: av_common: improve rounding for float->int timestamp conversions --- common/av_common.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'common') diff --git a/common/av_common.c b/common/av_common.c index e40c751e9f..6856a27d93 100644 --- a/common/av_common.c +++ b/common/av_common.c @@ -97,8 +97,10 @@ union pts { int64_t i; double d; }; int64_t mp_pts_to_av(double mp_pts, AVRational *tb) { assert(sizeof(int64_t) >= sizeof(double)); - if (tb && tb->num > 0 && tb->den > 0) - return mp_pts == MP_NOPTS_VALUE ? AV_NOPTS_VALUE : mp_pts / av_q2d(*tb); + if (tb && tb->num > 0 && tb->den > 0) { + return mp_pts == MP_NOPTS_VALUE ? + AV_NOPTS_VALUE : llrint(mp_pts / av_q2d(*tb)); + } // The + 0.0 is to squash possible negative zero mp_pts, which would // happen to end up as AV_NOPTS_VALUE. return (union pts){.d = mp_pts + 0.0}.i; -- cgit v1.2.3