From 98e7b4e538d42b6df1aa3c5f4a4c6c162a06b737 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 10 Nov 2016 11:44:20 +0100 Subject: av_common: always make sure to return a valid timebase av_reduce(&num, &den, 1, 14112000, 1000000) can return num=0, den=1. This means a 1/14112000 timebase (as used by the mp3 demuxer) would become invalid. The intention of mp_get_codec_timebase() is to always return a valid timebase. av_reduce() probably does the logically correct thing - so add a fallback to the safe default timebase. Also, increase the av_reduce() parameter to INT_MAX. Let's just pray this doesn't cause any actual problems. libavformat does the same, but might be in a different position due to using av_rescale() etc., while we convert between fractional timestamps and floats. --- common/av_common.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'common') diff --git a/common/av_common.c b/common/av_common.c index 95c6947eb7..27a331927a 100644 --- a/common/av_common.c +++ b/common/av_common.c @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -104,7 +105,10 @@ AVRational mp_get_codec_timebase(struct mp_codec_params *c) tb.den *= (r.num + r.den - 1) / r.den; } - av_reduce(&tb.num, &tb.den, tb.num, tb.den, 1000000); + av_reduce(&tb.num, &tb.den, tb.num, tb.den, INT_MAX); + + if (tb.num < 1 || tb.den < 1) + tb = AV_TIME_BASE_Q; return tb; } -- cgit v1.2.3