diff --git a/src/vapoursynth.cpp b/src/vapoursynth.cpp index 4708b41..751f949 100644 --- a/src/vapoursynth.cpp +++ b/src/vapoursynth.cpp @@ -255,7 +255,7 @@ static void VS_CC CreateBestVideoSource(const VSMap *In, VSMap *Out, void *, VSC } int64_t CacheSize = vsapi->mapGetInt(In, "cachesize", 0, &err); - if (!err && CacheSize > 0) + if (!err && CacheSize >= 0) D->V->SetMaxCacheSize(CacheSize * 1024 * 1024); vsapi->createVideoFilter(Out, "VideoSource", &D->VI, BestVideoSourceGetFrame, BestVideoSourceFree, fmUnordered, nullptr, 0, D, Core); diff --git a/src/videosource.cpp b/src/videosource.cpp index 5d2af1f..c3f87bf 100644 --- a/src/videosource.cpp +++ b/src/videosource.cpp @@ -784,7 +784,7 @@ BestVideoFrame *BestVideoSource::GetFrame(int64_t N) { LWVideoDecoder *Decoder = Decoders[Index]; DecoderLastUse[Index] = DecoderSequenceNum++; - AVFrame *RetFrame = nullptr; + BestVideoFrame *RetFrame = nullptr; while (Decoder && Decoder->GetFrameNumber() <= N && Decoder->HasMoreFrames()) { int64_t FrameNumber = Decoder->GetFrameNumber(); @@ -798,6 +798,9 @@ BestVideoFrame *BestVideoSource::GetFrame(int64_t N) { } } + if (FrameNumber == N) + RetFrame = new BestVideoFrame(Frame); + Cache.emplace_front(FrameNumber, Frame); CacheSize += Cache.front().Size; @@ -805,9 +808,6 @@ BestVideoFrame *BestVideoSource::GetFrame(int64_t N) { CacheSize -= Cache.back().Size; Cache.pop_back(); } - - if (FrameNumber == N) - RetFrame = Frame; } else if (FrameNumber < N) { Decoder->SkipAVFrames(N - PreRoll - FrameNumber); } @@ -827,9 +827,7 @@ BestVideoFrame *BestVideoSource::GetFrame(int64_t N) { } } - if (RetFrame) - return new BestVideoFrame(RetFrame); - return nullptr; + return RetFrame; } BestVideoFrame *BestVideoSource::GetFrameExtendLast(int64_t N) {