diff options
author | Matthew Hoops | 2013-08-25 22:22:41 -0400 |
---|---|---|
committer | Matthew Hoops | 2013-08-28 00:05:18 -0400 |
commit | 254f0fcc0639c48228c776858e4d0986d5874c88 (patch) | |
tree | c56b580b5954964eee2fd32707db298216928ece | |
parent | 7a8689538adcfaafa193be6780557a7bd5e8643d (diff) | |
download | scummvm-rg350-254f0fcc0639c48228c776858e4d0986d5874c88.tar.gz scummvm-rg350-254f0fcc0639c48228c776858e4d0986d5874c88.tar.bz2 scummvm-rg350-254f0fcc0639c48228c776858e4d0986d5874c88.zip |
VIDEO: Improve accuracy of getFrameTime() and getFrameAtTime()
-rw-r--r-- | video/video_decoder.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/video/video_decoder.cpp b/video/video_decoder.cpp index 6424d6f37b..0ab1478727 100644 --- a/video/video_decoder.cpp +++ b/video/video_decoder.cpp @@ -531,10 +531,9 @@ Audio::Timestamp VideoDecoder::FixedRateVideoTrack::getFrameTime(uint frame) con if (frameRate == frameRate.toInt()) // The nice case (a whole number) return Audio::Timestamp(0, frame, frameRate.toInt()); - // Just convert to milliseconds. - Common::Rational time = frame * 1000; - time /= frameRate; - return Audio::Timestamp(time.toInt(), 1000); + // Convert as best as possible + Common::Rational time = frameRate.getInverse() * frame; + return Audio::Timestamp(0, time.getNumerator(), time.getDenominator()); } uint VideoDecoder::FixedRateVideoTrack::getFrameAtTime(const Audio::Timestamp &time) const { @@ -544,8 +543,10 @@ uint VideoDecoder::FixedRateVideoTrack::getFrameAtTime(const Audio::Timestamp &t if (frameRate == time.framerate()) return time.totalNumberOfFrames(); - // Default case - return (time.totalNumberOfFrames() * frameRate / time.framerate()).toInt(); + // Create the rational based on the time first to hopefully cancel out + // *something* when multiplying by the frameRate (which can be large in + // some AVI videos). + return (Common::Rational(time.totalNumberOfFrames(), time.framerate()) * frameRate).toInt(); } Audio::Timestamp VideoDecoder::FixedRateVideoTrack::getDuration() const { |