diff options
author | wm4 <wm4@nowhere> | 2016-11-10 11:44:20 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2016-11-10 12:06:17 +0100 |
commit | 98e7b4e538d42b6df1aa3c5f4a4c6c162a06b737 (patch) | |
tree | 66ebf1b3ae7dc438a2495691540a6867e26f0a89 | |
parent | ca175871cd509f5bd629597c1e0417d4243b9742 (diff) | |
download | mpv-98e7b4e538d42b6df1aa3c5f4a4c6c162a06b737.tar.bz2 mpv-98e7b4e538d42b6df1aa3c5f4a4c6c162a06b737.tar.xz |
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.
-rw-r--r-- | common/av_common.c | 6 |
1 files changed, 5 insertions, 1 deletions
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 <assert.h> #include <math.h> +#include <limits.h> #include <libavutil/common.h> #include <libavutil/log.h> @@ -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; } |