diff --git a/src/audio_provider_vs.cpp b/src/audio_provider_vs.cpp index 49b3c7e06..55151e896 100644 --- a/src/audio_provider_vs.cpp +++ b/src/audio_provider_vs.cpp @@ -56,6 +56,8 @@ public: VapoursynthAudioProvider::VapoursynthAudioProvider(agi::fs::path const& filename) try { std::lock_guard lock(vs.GetMutex()); + VSCleanCache(); + script = vs.GetScriptAPI()->createScript(nullptr); if (script == nullptr) { throw VapoursynthError("Error creating script API"); diff --git a/src/libresrc/default_config.json b/src/libresrc/default_config.json index 3e76c8e06..dbdc303a3 100644 --- a/src/libresrc/default_config.json +++ b/src/libresrc/default_config.json @@ -353,6 +353,12 @@ "Index All Tracks" : true, "Log Level" : "quiet" }, + "VapourSynth" : { + "Cache" : { + "Files" : 500, + "Size" : 1000 + } + }, "Video" : { "Cache" : { "Size" : 32 diff --git a/src/libresrc/osx/default_config.json b/src/libresrc/osx/default_config.json index 61a9e965a..412f13f50 100644 --- a/src/libresrc/osx/default_config.json +++ b/src/libresrc/osx/default_config.json @@ -353,6 +353,12 @@ "Index All Tracks" : true, "Log Level" : "quiet" }, + "VapourSynth" : { + "Cache" : { + "Files" : 500, + "Size" : 1000 + } + }, "Video" : { "Cache" : { "Size" : 32 diff --git a/src/vapoursynth_common.cpp b/src/vapoursynth_common.cpp index 83070111f..9a0e3ebe3 100644 --- a/src/vapoursynth_common.cpp +++ b/src/vapoursynth_common.cpp @@ -19,6 +19,7 @@ #include "vapoursynth_wrap.h" #include "options.h" +#include "utils.h" #include #include @@ -39,6 +40,7 @@ int OpenScriptOrVideo(const VSAPI *api, const VSSCRIPTAPI *sapi, VSScript *scrip throw VapoursynthError("Failed to create VSMap for script info"); SetStringVar(api, map, "filename", filename.string()); + SetStringVar(api, map, "__aegi_vscache", config::path->Decode("?local/vscache").string()); for (std::string dir : { "data", "dictionary", "local", "script", "temp", "user", }) // Don't include ?audio and ?video in here since these only hold the paths to the previous audio/video files. SetStringVar(api, map, "__aegi_" + dir, config::path->Decode("?" + dir).string()); @@ -58,4 +60,11 @@ int OpenScriptOrVideo(const VSAPI *api, const VSSCRIPTAPI *sapi, VSScript *scrip return result; } +void VSCleanCache() { + CleanCache(config::path->Decode("?local/vscache/"), + "", + OPT_GET("Provider/VapourSynth/Cache/Size")->GetInt(), + OPT_GET("Provider/VapourSynth/Cache/Files")->GetInt()); +} + #endif // WITH_VAPOURSYNTH diff --git a/src/vapoursynth_common.h b/src/vapoursynth_common.h index 2f03b4e7b..af35da3aa 100644 --- a/src/vapoursynth_common.h +++ b/src/vapoursynth_common.h @@ -20,5 +20,6 @@ #include int OpenScriptOrVideo(const VSAPI *api, const VSSCRIPTAPI *sapi, VSScript *script, agi::fs::path const& filename, std::string default_script); +void VSCleanCache(); #endif // WITH_VAPOURSYNTH diff --git a/src/video_provider_vs.cpp b/src/video_provider_vs.cpp index 7b0d29449..7650a5045 100644 --- a/src/video_provider_vs.cpp +++ b/src/video_provider_vs.cpp @@ -111,6 +111,8 @@ void VapoursynthVideoProvider::SetResizeArg(VSMap *args, const VSMap *props, con VapoursynthVideoProvider::VapoursynthVideoProvider(agi::fs::path const& filename, std::string const& colormatrix) try { std::lock_guard lock(vs.GetMutex()); + VSCleanCache(); + script = vs.GetScriptAPI()->createScript(nullptr); if (script == nullptr) { throw VapoursynthError("Error creating script API");