From eace9f5efd94e98dd3bc132a836c9dc4ed649d2c Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Fri, 12 Oct 2012 20:50:28 -0500 Subject: [PATCH] Fixed a regression with disabling seek on the FFmpegReader. It runs slower than seeking, but has no artifacts of seeking, and is frame accurate. --- include/FFmpegReader.h | 5 ++++- src/FFmpegReader.cpp | 19 ++++++++++++++----- src/Main.cpp | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/include/FFmpegReader.h b/include/FFmpegReader.h index e04d5e1f..2a03ad17 100644 --- a/include/FFmpegReader.h +++ b/include/FFmpegReader.h @@ -177,9 +177,12 @@ namespace openshot /// frame 1, or it throws one of the following exceptions. FFmpegReader(string path) throw(InvalidFile, NoStreamsFound, InvalidCodec); - /// Close File + /// Close File & clear cache void Close(); + /// Close File + void Close(bool clear_cache); + /// Get an openshot::Frame object for a specific frame number of this reader. /// /// @returns The requested frame of video diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp index 5e06e4fe..873ddaff 100644 --- a/src/FFmpegReader.cpp +++ b/src/FFmpegReader.cpp @@ -138,6 +138,12 @@ void FFmpegReader::Open() throw(InvalidFile, NoStreamsFound, InvalidCodec) } void FFmpegReader::Close() +{ + // Close reader and clear cache + Close(true); +} + +void FFmpegReader::Close(bool clear_cache) { // Close all objects, if reader is 'open' if (is_open) @@ -157,9 +163,12 @@ void FFmpegReader::Close() avcodec_close(aCodecCtx); } - // Clear cache + // Clear final cache (based on the parameter) + if (clear_cache) + final_cache.Clear(); + + // Always clear temp cache working_cache.Clear(); - final_cache.Clear(); // Close the video file avformat_close_input(&pFormatCtx); @@ -327,7 +336,7 @@ Frame* FFmpegReader::GetFrame(int requested_frame) throw(ReaderClosed, TooManySe else if (!enable_seek && diff < 0) { // Start over, since we can't seek, and the requested frame is smaller than our position - Close(); + Close(false); Open(); } @@ -888,11 +897,11 @@ void FFmpegReader::Seek(int requested_frame) throw(TooManySeeks) throw TooManySeeks("Too many seek attempts... something seems wrong.", path); // If seeking to frame 1, we need to close and re-open the file (this is more reliable than seeking) - int buffer_amount = 10; + int buffer_amount = 5; if (requested_frame - buffer_amount <= 1) { // Close and re-open file (basically seeking to frame 1) - Close(); + Close(false); // do not clear cache Open(); // Not actually seeking, so clear these flags diff --git a/src/Main.cpp b/src/Main.cpp index 0d6b8e04..3cc9c925 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -18,7 +18,7 @@ int main() Timeline t(640, 360, Framerate(24,1)); // Add some clips - Clip c1("/home/jonathan/Videos/sintel_trailer-720p.mp4"); + Clip c1("/home/jonathan/Videos/sintel-1024-stereo.mp4"); c1.Position(0.0); //c1.time.AddPoint(500, 500, LINEAR);