From f947df7deda47f65d8e1dcbb2830e072e4dda9ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Thu, 7 Jan 2010 01:12:47 +0000 Subject: [PATCH] Slightly more precise calculations in finding keyframes/seeking. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34928 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../media/plugins/ffmpeg/AVFormatReader.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp b/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp index f1f6d30bb9..92cc9fdd01 100644 --- a/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp +++ b/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp @@ -788,7 +788,7 @@ AVFormatReader::StreamCookie::Seek(uint32 flags, int64* frame, uint32_t seekFlags = incr < 0 ? AVSEEK_FLAG_BACKWARD : 0; pos = av_rescale_q(pos, AV_TIME_BASE_Q, fStream->time_base); - + ret = av_seek_frame(fContext, Index(), pos, seekFlags); #endif @@ -839,17 +839,18 @@ AVFormatReader::StreamCookie::FindKeyFrame(uint32 flags, int64* frame, if ((flags & B_MEDIA_SEEK_TO_FRAME) != 0) *time = (bigtime_t)(*frame * 1000000LL / frameRate); - double timeBase = av_q2d(fStream->time_base); int64_t timeStamp; if ((flags & B_MEDIA_SEEK_TO_FRAME) != 0) { // Can use frame, because stream timeStamp is actually in frame // units. timeStamp = *frame; - } else - timeStamp = (int64_t)(*time / timeBase / 1000000.0); + } else { + timeStamp = *time * fStream->time_base.num + / ((int64_t)fStream->time_base.den * 1000000); + } - TRACE_SEEK(" time: %.2fs -> %lld (time_base: %f)\n", *time / 1000000.0, - timeStamp, timeBase); + TRACE_SEEK(" time: %.2fs -> %lld (time_base: %d/%d)\n", *time / 1000000.0, + timeStamp, fStream->time_base.num, fStream->time_base.den); int searchFlags = AVSEEK_FLAG_BACKWARD; if ((flags & B_MEDIA_SEEK_CLOSEST_FORWARD) != 0) @@ -867,7 +868,8 @@ AVFormatReader::StreamCookie::FindKeyFrame(uint32 flags, int64* frame, const AVIndexEntry& entry = fStream->index_entries[index]; timeStamp = entry.timestamp; - *time = (bigtime_t)(timeStamp * 1000000.0 * timeBase); + *time = (bigtime_t)(timeStamp * 1000000 * fStream->time_base.num + / fStream->time_base.den); TRACE_SEEK(" seeked time: %.2fs (%lld)\n", *time / 1000000.0, timeStamp); if ((flags & B_MEDIA_SEEK_TO_FRAME) != 0) {