From 2ec8106809a59425df29ed85f825737e58a0a50d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 14 Jun 2013 17:56:27 -0700 Subject: [PATCH] Ensure FFmpeg doesn't corrupt an early keyframe. When the analyze func runs, it seems to check between 2-4% (or so?) of the stream, which for longer videos especially we don't have yet. Returning a read failure here seems to truncate that keyframe sometimes. FFmpeg asks for the total size when this happens, which we were ignoring. Handling it fixes this, as FFmpeg apparently realizes we ran out of data. --- Core/HW/MediaEngine.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Core/HW/MediaEngine.cpp b/Core/HW/MediaEngine.cpp index f0cc59bbc..18621c196 100644 --- a/Core/HW/MediaEngine.cpp +++ b/Core/HW/MediaEngine.cpp @@ -166,6 +166,13 @@ int64_t _MpegSeekbuffer(void *opaque, int64_t offset, int whence) case SEEK_END: mpeg->m_decodeNextPos = mpeg->m_streamSize - (u32)offset; break; + +#ifdef USE_FFMPEG + // Don't seek, just return the full size. + // Returning this means FFmpeg won't think frames are truncated if we don't have them yet. + case AVSEEK_SIZE: + return mpeg->m_streamSize; +#endif } return offset; }