From af9d659c93804c9a441b5ffe306aadd5ea7192c2 Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Thu, 16 Mar 2023 02:16:13 +0100 Subject: [PATCH 1/4] vapoursynth: Add try_get_keyframes function to aegisub_vs.py --- automation/vapoursynth/aegisub_vs.py | 10 ++++++++++ src/libresrc/default_config.json | 2 +- src/libresrc/osx/default_config.json | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/automation/vapoursynth/aegisub_vs.py b/automation/vapoursynth/aegisub_vs.py index 166802adf..ebdaac199 100644 --- a/automation/vapoursynth/aegisub_vs.py +++ b/automation/vapoursynth/aegisub_vs.py @@ -216,6 +216,16 @@ def save_keyframes(filename: str, keyframes: List[int]): f.write("".join(f"{n}\n" for n in keyframes)) +def try_get_keyframes(filename: str, default: str | List[int]) -> str | List[int]: + """ + Checks if a keyframes file for the given filename is present and, if so, + returns it. Otherwise, returns the given list of keyframes. + """ + kffilename = make_keyframes_filename(filename) + + return kffilename if os.path.exists(kffilename) else default + + def get_keyframes(filename: str, clip: vs.VideoNode, **kwargs: Any) -> str: """ When not already present, creates a keyframe file for the given clip next diff --git a/src/libresrc/default_config.json b/src/libresrc/default_config.json index 1fab96699..c075789eb 100644 --- a/src/libresrc/default_config.json +++ b/src/libresrc/default_config.json @@ -374,7 +374,7 @@ }, "VapourSynth" : { "Log Level": "Information", - "Default Script" : "# This default script will load a video file using LWLibavSource.\n# It requires the `lsmas` plugin.\n# See ?data/automation/vapoursynth/aegisub_vs.py for more information.\n\nimport vapoursynth as vs\nimport time\nimport aegisub_vs as a\na.set_paths(locals())\n\nclip, videoinfo = a.wrap_lwlibavsource(filename)\nclip.set_output()\n__aegi_timecodes = videoinfo[\"timecodes\"]\n__aegi_keyframes = videoinfo[\"keyframes\"]\n# Uncomment this to automatically generate keyframes at scene changes.\n#__aegi_keyframes = a.get_keyframes(filename, clip)\n\n# Check if the file has an audio track. This requires the `bas` plugin.\n__aegi_hasaudio = 1 if a.check_audio(filename) else 0" + "Default Script" : "# This default script will load a video file using LWLibavSource.\n# It requires the `lsmas` plugin.\n# See ?data/automation/vapoursynth/aegisub_vs.py for more information.\n\nimport vapoursynth as vs\nimport time\nimport aegisub_vs as a\na.set_paths(locals())\n\nclip, videoinfo = a.wrap_lwlibavsource(filename)\nclip.set_output()\n__aegi_timecodes = videoinfo[\"timecodes\"]\n__aegi_keyframes = videoinfo[\"keyframes\"]\n\n# Uncomment the first following line to read keyframes from a file when present.\n#__aegi_keyframes = a.try_get_keyframes(filename, __aegi_keyframes)\n\n# Uncomment the following line to automatically generate keyframes at scene changes. This will take some time when first loading a video.\n#__aegi_keyframes = a.get_keyframes(filename, clip)\n\n# Check if the file has an audio track. This requires the `bas` plugin.\n__aegi_hasaudio = 1 if a.check_audio(filename) else 0" } } }, diff --git a/src/libresrc/osx/default_config.json b/src/libresrc/osx/default_config.json index 40db6b02e..a05c04f68 100644 --- a/src/libresrc/osx/default_config.json +++ b/src/libresrc/osx/default_config.json @@ -374,7 +374,7 @@ }, "VapourSynth" : { "Log Level": "Information", - "Default Script" : "# This default script will load a video file using LWLibavSource.\n# It requires the `lsmas` plugin.\n# See ?data/automation/vapoursynth/aegisub_vs.py for more information.\n\nimport vapoursynth as vs\nimport time\nimport aegisub_vs as a\na.set_paths(locals())\n\nclip, videoinfo = a.wrap_lwlibavsource(filename)\nclip.set_output()\n__aegi_timecodes = videoinfo[\"timecodes\"]\n__aegi_keyframes = videoinfo[\"keyframes\"]\n# Uncomment this to automatically generate keyframes at scene changes.\n#__aegi_keyframes = a.get_keyframes(filename, clip)\n\n# Check if the file has an audio track. This requires the `bas` plugin.\n__aegi_hasaudio = 1 if a.check_audio(filename) else 0" + "Default Script" : "# This default script will load a video file using LWLibavSource.\n# It requires the `lsmas` plugin.\n# See ?data/automation/vapoursynth/aegisub_vs.py for more information.\n\nimport vapoursynth as vs\nimport time\nimport aegisub_vs as a\na.set_paths(locals())\n\nclip, videoinfo = a.wrap_lwlibavsource(filename)\nclip.set_output()\n__aegi_timecodes = videoinfo[\"timecodes\"]\n__aegi_keyframes = videoinfo[\"keyframes\"]\n\n# Uncomment the first following line to read keyframes from a file when present.\n#__aegi_keyframes = a.try_get_keyframes(filename, __aegi_keyframes)\n\n# Uncomment the following line to automatically generate keyframes at scene changes. This will take some time when first loading a video.\n#__aegi_keyframes = a.get_keyframes(filename, clip)\n\n# Check if the file has an audio track. This requires the `bas` plugin.\n__aegi_hasaudio = 1 if a.check_audio(filename) else 0" } } }, From 9a7314015fd491be99dcb2165b9c5c8d57f36276 Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Thu, 16 Mar 2023 02:22:59 +0100 Subject: [PATCH 2/4] vapoursynth: Unify capitalization --- automation/vapoursynth/aegisub_vs.py | 8 ++-- src/audio_provider_factory.cpp | 4 +- src/audio_provider_vs.cpp | 40 ++++++++--------- src/vapoursynth_common.cpp | 6 +-- src/vapoursynth_wrap.cpp | 10 ++--- src/vapoursynth_wrap.h | 2 +- src/video_provider_manager.cpp | 4 +- src/video_provider_vs.cpp | 66 ++++++++++++++-------------- subprojects/vapoursynth.wrap | 2 +- tools/win-installer-setup.ps1 | 2 +- 10 files changed, 72 insertions(+), 72 deletions(-) diff --git a/automation/vapoursynth/aegisub_vs.py b/automation/vapoursynth/aegisub_vs.py index ebdaac199..16b314c7f 100644 --- a/automation/vapoursynth/aegisub_vs.py +++ b/automation/vapoursynth/aegisub_vs.py @@ -1,14 +1,14 @@ """ -Utility functions for loading video files into Aegisub using the Vapoursynth +Utility functions for loading video files into Aegisub using the VapourSynth video provider. When encountering a file whose file extension is not .py or .vpy, the -Vapoursynth audio and video providers will execute the respective default +VapourSynth audio and video providers will execute the respective default script set in Aegisub's configuration, with the following string variables set: - filename: The path to the file that's being opened. - __aegi_data, __aegi_dictionary, __aegi_local, __aegi_script, __aegi_temp, __aegi_user: The values of ?data, ?dictionary, etc. respectively. -- __aegi_vscache: The path to a directory where the Vapoursynth script can +- __aegi_vscache: The path to a directory where the VapourSynth script can store cache files. This directory is cleaned by Aegisub when it gets too large (as defined by Aegisub's configuration). @@ -53,7 +53,7 @@ def set_paths(vars: dict): def ensure_plugin(name: str, loadname: str, errormsg: str): """ - Ensures that the Vapoursynth plugin with the given name exists. + Ensures that the VapourSynth plugin with the given name exists. If it doesn't, it tries to load it from `loadname`. If that fails, it raises an error with the given error message. """ diff --git a/src/audio_provider_factory.cpp b/src/audio_provider_factory.cpp index 71c34f66e..d2597cee4 100644 --- a/src/audio_provider_factory.cpp +++ b/src/audio_provider_factory.cpp @@ -32,7 +32,7 @@ using namespace agi; std::unique_ptr CreateAvisynthAudioProvider(fs::path const& filename, BackgroundRunner *); std::unique_ptr CreateFFmpegSourceAudioProvider(fs::path const& filename, BackgroundRunner *); std::unique_ptr CreateBSAudioProvider(fs::path const& filename, BackgroundRunner *); -std::unique_ptr CreateVapoursynthAudioProvider(fs::path const& filename, BackgroundRunner *); +std::unique_ptr CreateVapourSynthAudioProvider(fs::path const& filename, BackgroundRunner *); namespace { struct factory { @@ -54,7 +54,7 @@ const factory providers[] = { {"BestSource", CreateBSAudioProvider, false}, #endif #ifdef WITH_VAPOURSYNTH - {"Vapoursynth", CreateVapoursynthAudioProvider, false}, + {"VapourSynth", CreateVapourSynthAudioProvider, false}, #endif }; } diff --git a/src/audio_provider_vs.cpp b/src/audio_provider_vs.cpp index 1f42803be..2d81f06bb 100644 --- a/src/audio_provider_vs.cpp +++ b/src/audio_provider_vs.cpp @@ -15,7 +15,7 @@ // Aegisub Project http://www.aegisub.org/ /// @file audio_provider_vs.cpp -/// @brief Vapoursynth-based audio provider +/// @brief VapourSynth-based audio provider /// @ingroup audio_input /// @@ -38,7 +38,7 @@ #include "VSScript4.h" namespace { -class VapoursynthAudioProvider final : public agi::AudioProvider { +class VapourSynthAudioProvider final : public agi::AudioProvider { VapourSynthWrapper vs; VSScript *script = nullptr; VSNode *node = nullptr; @@ -47,36 +47,36 @@ class VapoursynthAudioProvider final : public agi::AudioProvider { void FillBufferWithFrame(void *buf, int frame, int64_t start, int64_t count) const; void FillBuffer(void *buf, int64_t start, int64_t count) const override; public: - VapoursynthAudioProvider(agi::fs::path const& filename); - ~VapoursynthAudioProvider(); + VapourSynthAudioProvider(agi::fs::path const& filename); + ~VapourSynthAudioProvider(); bool NeedsCache() const override { return true; } }; -VapoursynthAudioProvider::VapoursynthAudioProvider(agi::fs::path const& filename) try { +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"); + throw VapourSynthError("Error creating script API"); } vs.GetScriptAPI()->evalSetWorkingDir(script, 1); if (OpenScriptOrVideo(vs.GetAPI(), vs.GetScriptAPI(), script, filename, OPT_GET("Provider/Audio/VapourSynth/Default Script")->GetString())) { std::string msg = agi::format("Error executing VapourSynth script: %s", vs.GetScriptAPI()->getError(script)); vs.GetScriptAPI()->freeScript(script); - throw VapoursynthError(msg); + throw VapourSynthError(msg); } node = vs.GetScriptAPI()->getOutputNode(script, 0); if (node == nullptr) { vs.GetScriptAPI()->freeScript(script); - throw VapoursynthError("No output node set"); + throw VapourSynthError("No output node set"); } if (vs.GetAPI()->getNodeType(node) != mtAudio) { vs.GetAPI()->freeNode(node); vs.GetScriptAPI()->freeScript(script); - throw VapoursynthError("Output node isn't an audio node"); + throw VapourSynthError("Output node isn't an audio node"); } vi = vs.GetAPI()->getAudioInfo(node); float_samples = vi->format.sampleType == stFloat; @@ -85,10 +85,10 @@ VapoursynthAudioProvider::VapoursynthAudioProvider(agi::fs::path const& filename channels = vi->format.numChannels; num_samples = vi->numSamples; } -catch (VapoursynthError const& err) { +catch (VapourSynthError const& err) { // Unlike the video provider manager, the audio provider factory catches AudioProviderErrors and picks whichever source doesn't throw one. // So just rethrow the Error here with an extra label so the user will see the error message and know the audio wasn't loaded with VS - throw VapoursynthError(agi::format("Vapoursynth error: %s", err.GetMessage())); + throw VapourSynthError(agi::format("VapourSynth error: %s", err.GetMessage())); } template @@ -102,19 +102,19 @@ static void PackChannels(const uint8_t **Src, void *Dst, size_t Length, size_t C } } -void VapoursynthAudioProvider::FillBufferWithFrame(void *buf, int n, int64_t start, int64_t count) const { +void VapourSynthAudioProvider::FillBufferWithFrame(void *buf, int n, int64_t start, int64_t count) const { char errorMsg[1024]; const VSFrame *frame = vs.GetAPI()->getFrame(n, node, errorMsg, sizeof(errorMsg)); if (frame == nullptr) { - throw VapoursynthError(agi::format("Error getting frame: %s", errorMsg)); + throw VapourSynthError(agi::format("Error getting frame: %s", errorMsg)); } if (vs.GetAPI()->getFrameLength(frame) < count) { vs.GetAPI()->freeFrame(frame); - throw VapoursynthError("Audio frame too short"); + throw VapourSynthError("Audio frame too short"); } if (vs.GetAPI()->getAudioFrameFormat(frame)->numChannels != channels || vs.GetAPI()->getAudioFrameFormat(frame)->bytesPerSample != bytes_per_sample) { vs.GetAPI()->freeFrame(frame); - throw VapoursynthError("Audio format is not constant"); + throw VapourSynthError("Audio format is not constant"); } std::vector planes(channels); @@ -122,7 +122,7 @@ void VapoursynthAudioProvider::FillBufferWithFrame(void *buf, int n, int64_t sta planes[c] = vs.GetAPI()->getReadPtr(frame, c) + bytes_per_sample * start; if (planes[c] == nullptr) { vs.GetAPI()->freeFrame(frame); - throw VapoursynthError("Failed to read audio channel"); + throw VapourSynthError("Failed to read audio channel"); } } @@ -138,7 +138,7 @@ void VapoursynthAudioProvider::FillBufferWithFrame(void *buf, int n, int64_t sta vs.GetAPI()->freeFrame(frame); } -void VapoursynthAudioProvider::FillBuffer(void *buf, int64_t start, int64_t count) const { +void VapourSynthAudioProvider::FillBuffer(void *buf, int64_t start, int64_t count) const { int end = start + count; // exclusive int startframe = start / VS_AUDIO_FRAME_SAMPLES; int endframe = (end - 1) / VS_AUDIO_FRAME_SAMPLES; @@ -154,7 +154,7 @@ void VapoursynthAudioProvider::FillBuffer(void *buf, int64_t start, int64_t coun } } -VapoursynthAudioProvider::~VapoursynthAudioProvider() { +VapourSynthAudioProvider::~VapourSynthAudioProvider() { if (node != nullptr) { vs.GetAPI()->freeNode(node); } @@ -164,7 +164,7 @@ VapoursynthAudioProvider::~VapoursynthAudioProvider() { } } -std::unique_ptr CreateVapoursynthAudioProvider(agi::fs::path const& file, agi::BackgroundRunner *) { - return agi::make_unique(file); +std::unique_ptr CreateVapourSynthAudioProvider(agi::fs::path const& file, agi::BackgroundRunner *) { + return agi::make_unique(file); } #endif diff --git a/src/vapoursynth_common.cpp b/src/vapoursynth_common.cpp index 88a8446d2..e5346f6bc 100644 --- a/src/vapoursynth_common.cpp +++ b/src/vapoursynth_common.cpp @@ -28,7 +28,7 @@ void SetStringVar(const VSAPI *api, VSMap *map, std::string variable, std::string value) { if (api->mapSetData(map, variable.c_str(), value.c_str(), -1, dtUtf8, 1)) - throw VapoursynthError("Failed to set VSMap entry"); + throw VapourSynthError("Failed to set VSMap entry"); } int OpenScriptOrVideo(const VSAPI *api, const VSSCRIPTAPI *sapi, VSScript *script, agi::fs::path const& filename, std::string default_script) { @@ -38,7 +38,7 @@ int OpenScriptOrVideo(const VSAPI *api, const VSSCRIPTAPI *sapi, VSScript *scrip } else { VSMap *map = api->createMap(); if (map == nullptr) - throw VapoursynthError("Failed to create VSMap for script info"); + 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()); @@ -52,7 +52,7 @@ int OpenScriptOrVideo(const VSAPI *api, const VSSCRIPTAPI *sapi, VSScript *scrip SetStringVar(api, map, "__aegi_" + dir, config::path->Decode("?" + dir).string()); if (sapi->setVariables(script, map)) - throw VapoursynthError("Failed to set script info variables"); + throw VapourSynthError("Failed to set script info variables"); api->freeMap(map); diff --git a/src/vapoursynth_wrap.cpp b/src/vapoursynth_wrap.cpp index 33c7de659..f9f64add9 100644 --- a/src/vapoursynth_wrap.cpp +++ b/src/vapoursynth_wrap.cpp @@ -15,7 +15,7 @@ // Aegisub Project http://www.aegisub.org/ /// @file vapoursynth_wrap.cpp -/// @brief Wrapper-layer for Vapoursynth +/// @brief Wrapper-layer for VapourSynth /// @ingroup video_input audio_input /// @@ -67,7 +67,7 @@ VapourSynthWrapper::VapourSynthWrapper() { #endif if (!hLib) - throw VapoursynthError("Could not load " VSSCRIPT_SO); + throw VapourSynthError("Could not load " VSSCRIPT_SO); #ifdef _WIN32 FUNC* getVSScriptAPI = (FUNC*)GetProcAddress(hLib, "getVSScriptAPI"); @@ -75,7 +75,7 @@ VapourSynthWrapper::VapourSynthWrapper() { FUNC* getVSScriptAPI = (FUNC*)dlsym(hLib, "getVSScriptAPI"); #endif if (!getVSScriptAPI) - throw VapoursynthError("Failed to get address of getVSScriptAPI from " VSSCRIPT_SO); + throw VapourSynthError("Failed to get address of getVSScriptAPI from " VSSCRIPT_SO); // Python will set the program's locale to the user's default locale, which will break // half of wxwidgets on some operating systems due to locale mismatches. There's not really anything @@ -85,12 +85,12 @@ VapourSynthWrapper::VapourSynthWrapper() { setlocale(LC_ALL, oldlocale.c_str()); if (!scriptapi) - throw VapoursynthError("Failed to get Vapoursynth ScriptAPI"); + throw VapourSynthError("Failed to get VapourSynth ScriptAPI"); api = scriptapi->getVSAPI(VAPOURSYNTH_API_VERSION); if (!api) - throw VapoursynthError("Failed to get Vapoursynth API"); + throw VapourSynthError("Failed to get VapourSynth API"); vs_loaded = true; } diff --git a/src/vapoursynth_wrap.h b/src/vapoursynth_wrap.h index 802cb3d58..ee07235ff 100644 --- a/src/vapoursynth_wrap.h +++ b/src/vapoursynth_wrap.h @@ -23,7 +23,7 @@ #include -DEFINE_EXCEPTION(VapoursynthError, agi::Exception); +DEFINE_EXCEPTION(VapourSynthError, agi::Exception); struct VSAPI; struct VSSCRIPTAPI; diff --git a/src/video_provider_manager.cpp b/src/video_provider_manager.cpp index c239163b8..08a2f76b7 100644 --- a/src/video_provider_manager.cpp +++ b/src/video_provider_manager.cpp @@ -30,7 +30,7 @@ std::unique_ptr CreateYUV4MPEGVideoProvider(agi::fs::path const&, std::unique_ptr CreateFFmpegSourceVideoProvider(agi::fs::path const&, std::string const&, agi::BackgroundRunner *); std::unique_ptr CreateAvisynthVideoProvider(agi::fs::path const&, std::string const&, agi::BackgroundRunner *); std::unique_ptr CreateBSVideoProvider(agi::fs::path const&, std::string const&, agi::BackgroundRunner *); -std::unique_ptr CreateVapoursynthVideoProvider(agi::fs::path const&, std::string const&, agi::BackgroundRunner *); +std::unique_ptr CreateVapourSynthVideoProvider(agi::fs::path const&, std::string const&, agi::BackgroundRunner *); std::unique_ptr CreateCacheVideoProvider(std::unique_ptr); @@ -54,7 +54,7 @@ namespace { {"BestSource", CreateBSVideoProvider, false}, #endif #ifdef WITH_VAPOURSYNTH - {"Vapoursynth", CreateVapoursynthVideoProvider, false}, + {"VapourSynth", CreateVapourSynthVideoProvider, false}, #endif }; } diff --git a/src/video_provider_vs.cpp b/src/video_provider_vs.cpp index b08dd65a6..da4a3d1a5 100644 --- a/src/video_provider_vs.cpp +++ b/src/video_provider_vs.cpp @@ -42,7 +42,7 @@ static const char *tc_key = "__aegi_timecodes"; static const char *audio_key = "__aegi_hasaudio"; namespace { -class VapoursynthVideoProvider: public VideoProvider { +class VapourSynthVideoProvider: public VideoProvider { VapourSynthWrapper vs; VSScript *script = nullptr; VSNode *node = nullptr; @@ -59,8 +59,8 @@ class VapoursynthVideoProvider: public VideoProvider { void SetResizeArg(VSMap *args, const VSMap *props, const char *arg_name, const char *prop_name, int64_t deflt, int64_t unspecified = -1); public: - VapoursynthVideoProvider(agi::fs::path const& filename, std::string const& colormatrix, agi::BackgroundRunner *br); - ~VapoursynthVideoProvider(); + VapourSynthVideoProvider(agi::fs::path const& filename, std::string const& colormatrix, agi::BackgroundRunner *br); + ~VapourSynthVideoProvider(); void GetFrame(int n, VideoFrame &frame) override; @@ -105,7 +105,7 @@ std::string colormatrix_description(int colorFamily, int colorRange, int matrix) } // Adds an argument to the rescaler if the corresponding frameprop does not exist or is set as unspecified -void VapoursynthVideoProvider::SetResizeArg(VSMap *args, const VSMap *props, const char *arg_name, const char *prop_name, int64_t deflt, int64_t unspecified) { +void VapourSynthVideoProvider::SetResizeArg(VSMap *args, const VSMap *props, const char *arg_name, const char *prop_name, int64_t deflt, int64_t unspecified) { int err; int64_t result = vs.GetAPI()->mapGetInt(props, prop_name, 0, &err); if (err != 0 || result == unspecified) { @@ -117,7 +117,7 @@ void VapoursynthVideoProvider::SetResizeArg(VSMap *args, const VSMap *props, con } } -VapoursynthVideoProvider::VapoursynthVideoProvider(agi::fs::path const& filename, std::string const& colormatrix, agi::BackgroundRunner *br) try { try { +VapourSynthVideoProvider::VapourSynthVideoProvider(agi::fs::path const& filename, std::string const& colormatrix, agi::BackgroundRunner *br) try { try { std::lock_guard lock(vs.GetMutex()); VSCleanCache(); @@ -125,16 +125,16 @@ VapoursynthVideoProvider::VapoursynthVideoProvider(agi::fs::path const& filename int err1, err2; VSCore *core = vs.GetAPI()->createCore(0); if (core == nullptr) { - throw VapoursynthError("Error creating core"); + throw VapourSynthError("Error creating core"); } script = vs.GetScriptAPI()->createScript(core); if (script == nullptr) { vs.GetAPI()->freeCore(core); - throw VapoursynthError("Error creating script API"); + throw VapourSynthError("Error creating script API"); } vs.GetScriptAPI()->evalSetWorkingDir(script, 1); br->Run([&](agi::ProgressSink *ps) { - ps->SetTitle(from_wx(_("Executing Vapoursynth Script"))); + ps->SetTitle(from_wx(_("Executing VapourSynth Script"))); ps->SetMessage(""); ps->SetIndeterminate(); @@ -148,20 +148,20 @@ VapoursynthVideoProvider::VapoursynthVideoProvider(agi::fs::path const& filename }); if (err1) { std::string msg = agi::format("Error executing VapourSynth script: %s", vs.GetScriptAPI()->getError(script)); - throw VapoursynthError(msg); + throw VapourSynthError(msg); } node = vs.GetScriptAPI()->getOutputNode(script, 0); if (node == nullptr) - throw VapoursynthError("No output node set"); + throw VapourSynthError("No output node set"); if (vs.GetAPI()->getNodeType(node) != mtVideo) { - throw VapoursynthError("Output node isn't a video node"); + throw VapourSynthError("Output node isn't a video node"); } vi = vs.GetAPI()->getVideoInfo(node); if (vi == nullptr) - throw VapoursynthError("Couldn't get video info"); + throw VapourSynthError("Couldn't get video info"); if (!vsh::isConstantVideoFormat(vi)) - throw VapoursynthError("Video doesn't have constant format"); + throw VapourSynthError("Video doesn't have constant format"); int fpsNum = vi->fpsNum; int fpsDen = vi->fpsDen; @@ -174,7 +174,7 @@ VapoursynthVideoProvider::VapoursynthVideoProvider(agi::fs::path const& filename // Get timecodes and/or keyframes if provided VSMap *clipinfo = vs.GetAPI()->createMap(); if (clipinfo == nullptr) - throw VapoursynthError("Couldn't create map"); + throw VapourSynthError("Couldn't create map"); vs.GetScriptAPI()->getVariable(script, kf_key, clipinfo); vs.GetScriptAPI()->getVariable(script, tc_key, clipinfo); vs.GetScriptAPI()->getVariable(script, audio_key, clipinfo); @@ -190,7 +190,7 @@ VapoursynthVideoProvider::VapoursynthVideoProvider(agi::fs::path const& filename const int64_t *kfs = vs.GetAPI()->mapGetIntArray(clipinfo, kf_key, &err1); const char *kfs_path = vs.GetAPI()->mapGetData(clipinfo, kf_key, 0, &err2); if (err1 && err2) - throw VapoursynthError("Error getting keyframes from returned VSMap"); + throw VapourSynthError("Error getting keyframes from returned VSMap"); if (!err1) { keyframes.reserve(numkf); @@ -199,7 +199,7 @@ VapoursynthVideoProvider::VapoursynthVideoProvider(agi::fs::path const& filename } else { int kfs_path_size = vs.GetAPI()->mapGetDataSize(clipinfo, kf_key, 0, &err1); if (err1) - throw VapoursynthError("Error getting size of keyframes path"); + throw VapourSynthError("Error getting size of keyframes path"); try { keyframes = agi::keyframe::Load(config::path->Decode(std::string(kfs_path, size_t(kfs_path_size)))); @@ -213,11 +213,11 @@ VapoursynthVideoProvider::VapoursynthVideoProvider(agi::fs::path const& filename const int64_t *tcs = vs.GetAPI()->mapGetIntArray(clipinfo, tc_key, &err1); const char *tcs_path = vs.GetAPI()->mapGetData(clipinfo, tc_key, 0, &err2); if (err1 && err2) - throw VapoursynthError("Error getting timecodes from returned map"); + throw VapourSynthError("Error getting timecodes from returned map"); if (!err1) { if (numtc != vi->numFrames) - throw VapoursynthError("Number of returned timecodes does not match number of frames"); + throw VapourSynthError("Number of returned timecodes does not match number of frames"); std::vector timecodes; timecodes.reserve(numtc); @@ -228,13 +228,13 @@ VapoursynthVideoProvider::VapoursynthVideoProvider(agi::fs::path const& filename } else { int tcs_path_size = vs.GetAPI()->mapGetDataSize(clipinfo, tc_key, 0, &err1); if (err1) - throw VapoursynthError("Error getting size of keyframes path"); + throw VapourSynthError("Error getting size of keyframes path"); try { fps = agi::vfr::Framerate(config::path->Decode(std::string(tcs_path, size_t(tcs_path_size)))); } catch (agi::Exception const& e) { // Throw an error here unlike with keyframes since the timecodes not being loaded might not be immediately noticeable - throw VapoursynthError("Failed to open timecodes file specified by script: " + e.GetMessage()); + throw VapourSynthError("Failed to open timecodes file specified by script: " + e.GetMessage()); } } } @@ -245,7 +245,7 @@ VapoursynthVideoProvider::VapoursynthVideoProvider(agi::fs::path const& filename const VSMap *props = vs.GetAPI()->getFramePropertiesRO(frame); if (props == nullptr) - throw VapoursynthError("Couldn't get frame properties"); + throw VapourSynthError("Couldn't get frame properties"); int64_t sarn = vs.GetAPI()->mapGetInt(props, "_SARNum", 0, &err1); int64_t sard = vs.GetAPI()->mapGetInt(props, "_SARDen", 0, &err2); if (!err1 && !err2) { @@ -262,11 +262,11 @@ VapoursynthVideoProvider::VapoursynthVideoProvider(agi::fs::path const& filename // Convert to RGB24 format VSPlugin *resize = vs.GetAPI()->getPluginByID(VSH_RESIZE_PLUGIN_ID, vs.GetScriptAPI()->getCore(script)); if (resize == nullptr) - throw VapoursynthError("Couldn't find resize plugin"); + throw VapourSynthError("Couldn't find resize plugin"); VSMap *args = vs.GetAPI()->createMap(); if (args == nullptr) - throw VapoursynthError("Failed to create argument map"); + throw VapourSynthError("Failed to create argument map"); vs.GetAPI()->mapSetNode(args, "clip", node, maAppend); vs.GetAPI()->mapSetInt(args, "format", pfRGB24, maAppend); @@ -299,7 +299,7 @@ VapoursynthVideoProvider::VapoursynthVideoProvider(agi::fs::path const& filename const VSFrame *rgbframe = GetVSFrame(0); vs.GetAPI()->freeFrame(rgbframe); } -} catch (VapoursynthError const& err) { // for try inside of function. We need both here since we need to catch errors from the VapoursynthWrap constructor. +} catch (VapourSynthError const& err) { // for try inside of function. We need both here since we need to catch errors from the VapourSynthWrap constructor. if (node != nullptr) vs.GetAPI()->freeNode(node); if (script != nullptr) @@ -307,27 +307,27 @@ VapoursynthVideoProvider::VapoursynthVideoProvider(agi::fs::path const& filename throw err; } } -catch (VapoursynthError const& err) { // for the entire constructor - throw VideoProviderError(agi::format("Vapoursynth error: %s", err.GetMessage())); +catch (VapourSynthError const& err) { // for the entire constructor + throw VideoProviderError(agi::format("VapourSynth error: %s", err.GetMessage())); } -const VSFrame *VapoursynthVideoProvider::GetVSFrame(int n) { +const VSFrame *VapourSynthVideoProvider::GetVSFrame(int n) { char errorMsg[1024]; const VSFrame *frame = vs.GetAPI()->getFrame(n, node, errorMsg, sizeof(errorMsg)); if (frame == nullptr) { - throw VapoursynthError(agi::format("Error getting frame: %s", errorMsg)); + throw VapourSynthError(agi::format("Error getting frame: %s", errorMsg)); } return frame; } -void VapoursynthVideoProvider::GetFrame(int n, VideoFrame &out) { +void VapourSynthVideoProvider::GetFrame(int n, VideoFrame &out) { std::lock_guard lock(vs.GetMutex()); const VSFrame *frame = GetVSFrame(n); const VSVideoFormat *format = vs.GetAPI()->getVideoFrameFormat(frame); if (format->colorFamily != cfRGB || format->numPlanes != 3 || format->bitsPerSample != 8 || format->subSamplingH != 0 || format->subSamplingW != 0) { - throw VapoursynthError("Frame not in RGB24 format"); + throw VapourSynthError("Frame not in RGB24 format"); } out.width = vs.GetAPI()->getFrameWidth(frame, 0); @@ -359,7 +359,7 @@ void VapoursynthVideoProvider::GetFrame(int n, VideoFrame &out) { vs.GetAPI()->freeFrame(frame); } -VapoursynthVideoProvider::~VapoursynthVideoProvider() { +VapourSynthVideoProvider::~VapourSynthVideoProvider() { if (node != nullptr) { vs.GetAPI()->freeNode(node); } @@ -370,7 +370,7 @@ VapoursynthVideoProvider::~VapoursynthVideoProvider() { } namespace agi { class BackgroundRunner; } -std::unique_ptr CreateVapoursynthVideoProvider(agi::fs::path const& path, std::string const& colormatrix, agi::BackgroundRunner *br) { - return agi::make_unique(path, colormatrix, br); +std::unique_ptr CreateVapourSynthVideoProvider(agi::fs::path const& path, std::string const& colormatrix, agi::BackgroundRunner *br) { + return agi::make_unique(path, colormatrix, br); } #endif // WITH_VAPOURSYNTH diff --git a/subprojects/vapoursynth.wrap b/subprojects/vapoursynth.wrap index 592446ccf..1db0de4a5 100644 --- a/subprojects/vapoursynth.wrap +++ b/subprojects/vapoursynth.wrap @@ -1,4 +1,4 @@ [wrap-git] -url = https://github.com/Vapoursynth/vapoursynth.git +url = https://github.com/vapoursynth/vapoursynth.git revision = R59 patch_directory = vapoursynth diff --git a/tools/win-installer-setup.ps1 b/tools/win-installer-setup.ps1 index 20684511e..d1a7b0987 100644 --- a/tools/win-installer-setup.ps1 +++ b/tools/win-installer-setup.ps1 @@ -58,7 +58,7 @@ if (!(Test-Path VSFilter)) { Set-Location $DepsDir } -### Vapoursynth plugins +### VapourSynth plugins # L-SMASH-Works if (!(Test-Path L-SMASH-Works)) { From 178551071eeff801dbecde8d4372d1ce4852b1fa Mon Sep 17 00:00:00 2001 From: LightArrowsEXE Date: Thu, 16 Mar 2023 04:29:12 +0100 Subject: [PATCH 3/4] make_keyframes: Set default format to GRAY8 This will allow clips with non-standard resolutions to be downscaled without any concerns. --- automation/vapoursynth/aegisub_vs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automation/vapoursynth/aegisub_vs.py b/automation/vapoursynth/aegisub_vs.py index 16b314c7f..1eca5f5d3 100644 --- a/automation/vapoursynth/aegisub_vs.py +++ b/automation/vapoursynth/aegisub_vs.py @@ -167,7 +167,7 @@ def wrap_lwlibavsource(filename: str, cachedir: str | None = None, **kwargs: Any def make_keyframes(clip: vs.VideoNode, use_scxvid: bool = False, - resize_h: int = 360, resize_format: int = vs.YUV420P8, + resize_h: int = 360, resize_format: int = vs.GRAY8, **kwargs: Any) -> List[int]: """ Generates a list of keyframes from a clip, using either WWXD or Scxvid. @@ -181,7 +181,7 @@ def make_keyframes(clip: vs.VideoNode, use_scxvid: bool = False, The remaining keyword arguments are passed on to the respective filter. """ - clip = core.resize.Bilinear(clip, width=resize_h * clip.width // clip.height, height=resize_h, format=resize_format); + clip = core.resize.Bilinear(clip, width=resize_h * clip.width // clip.height, height=resize_h, format=resize_format) if use_scxvid: ensure_plugin("scxvid", "libscxvid", "To use the keyframe generation, the scxvid plugin for VapourSynth must be installed") From 3d278547fec14ae76e3f497fc78c9e5be7ebedc0 Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Sat, 29 Apr 2023 21:24:14 +0200 Subject: [PATCH 4/4] vapoursynth: Add Mac support --- .github/workflows/ci.yml | 4 ++-- src/vapoursynth_wrap.cpp | 10 +++++++--- src/vapoursynth_wrap.h | 3 ++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9f8e10507..7cf4dbc6d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,13 +53,13 @@ jobs: name: macOS Debug, os: macos-latest, buildtype: debugoptimized, - args: -Ddefault_library=static -Dbuild_osx_bundle=true -Dlocal_boost=true + args: -Ddefault_library=static -Dbuild_osx_bundle=true -Dlocal_boost=true -Dvapoursynth=enabled } - { name: macOS Release, os: macos-latest, buildtype: release, - args: -Ddefault_library=static -Dbuild_osx_bundle=true -Dlocal_boost=true + args: -Ddefault_library=static -Dbuild_osx_bundle=true -Dlocal_boost=true -Dvapoursynth=enabled } steps: diff --git a/src/vapoursynth_wrap.cpp b/src/vapoursynth_wrap.cpp index f9f64add9..8bbbccbbf 100644 --- a/src/vapoursynth_wrap.cpp +++ b/src/vapoursynth_wrap.cpp @@ -26,8 +26,6 @@ #include "options.h" -#include - #ifndef _WIN32 #include #endif @@ -35,7 +33,13 @@ #ifdef _WIN32 #define VSSCRIPT_SO "vsscript.dll" #else +#ifdef __APPLE__ +#define VSSCRIPT_SO "libvapoursynth-script.dylib" +#define DLOPEN_FLAGS RTLD_LAZY | RTLD_GLOBAL +#else #define VSSCRIPT_SO "libvapoursynth-script.so" +#define DLOPEN_FLAGS RTLD_LAZY | RTLD_GLOBAL | RTLD_DEEPBIND +#endif #endif // Allocate storage for and initialise static members @@ -63,7 +67,7 @@ VapourSynthWrapper::VapourSynthWrapper() { #undef _Lstr #undef CONCATENATE #else - hLib = dlopen(VSSCRIPT_SO, RTLD_LAZY | RTLD_GLOBAL | RTLD_DEEPBIND); + hLib = dlopen(VSSCRIPT_SO, DLOPEN_FLAGS); #endif if (!hLib) diff --git a/src/vapoursynth_wrap.h b/src/vapoursynth_wrap.h index ee07235ff..2d663e7c5 100644 --- a/src/vapoursynth_wrap.h +++ b/src/vapoursynth_wrap.h @@ -21,13 +21,14 @@ #ifdef WITH_VAPOURSYNTH +#include + #include DEFINE_EXCEPTION(VapourSynthError, agi::Exception); struct VSAPI; struct VSSCRIPTAPI; -namespace std { class mutex; } class VapourSynthWrapper { VapourSynthWrapper(VapourSynthWrapper const&);