mirror of https://github.com/odrling/Aegisub
vapoursynth: Unify capitalization
This commit is contained in:
parent
af9d659c93
commit
9a7314015f
|
@ -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.
|
video provider.
|
||||||
|
|
||||||
When encountering a file whose file extension is not .py or .vpy, the
|
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:
|
script set in Aegisub's configuration, with the following string variables set:
|
||||||
- filename: The path to the file that's being opened.
|
- filename: The path to the file that's being opened.
|
||||||
- __aegi_data, __aegi_dictionary, __aegi_local, __aegi_script, __aegi_temp, __aegi_user:
|
- __aegi_data, __aegi_dictionary, __aegi_local, __aegi_script, __aegi_temp, __aegi_user:
|
||||||
The values of ?data, ?dictionary, etc. respectively.
|
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
|
store cache files. This directory is cleaned by Aegisub when it gets too
|
||||||
large (as defined by Aegisub's configuration).
|
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):
|
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 it doesn't, it tries to load it from `loadname`.
|
||||||
If that fails, it raises an error with the given error message.
|
If that fails, it raises an error with the given error message.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -32,7 +32,7 @@ using namespace agi;
|
||||||
std::unique_ptr<AudioProvider> CreateAvisynthAudioProvider(fs::path const& filename, BackgroundRunner *);
|
std::unique_ptr<AudioProvider> CreateAvisynthAudioProvider(fs::path const& filename, BackgroundRunner *);
|
||||||
std::unique_ptr<AudioProvider> CreateFFmpegSourceAudioProvider(fs::path const& filename, BackgroundRunner *);
|
std::unique_ptr<AudioProvider> CreateFFmpegSourceAudioProvider(fs::path const& filename, BackgroundRunner *);
|
||||||
std::unique_ptr<AudioProvider> CreateBSAudioProvider(fs::path const& filename, BackgroundRunner *);
|
std::unique_ptr<AudioProvider> CreateBSAudioProvider(fs::path const& filename, BackgroundRunner *);
|
||||||
std::unique_ptr<AudioProvider> CreateVapoursynthAudioProvider(fs::path const& filename, BackgroundRunner *);
|
std::unique_ptr<AudioProvider> CreateVapourSynthAudioProvider(fs::path const& filename, BackgroundRunner *);
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct factory {
|
struct factory {
|
||||||
|
@ -54,7 +54,7 @@ const factory providers[] = {
|
||||||
{"BestSource", CreateBSAudioProvider, false},
|
{"BestSource", CreateBSAudioProvider, false},
|
||||||
#endif
|
#endif
|
||||||
#ifdef WITH_VAPOURSYNTH
|
#ifdef WITH_VAPOURSYNTH
|
||||||
{"Vapoursynth", CreateVapoursynthAudioProvider, false},
|
{"VapourSynth", CreateVapourSynthAudioProvider, false},
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
// Aegisub Project http://www.aegisub.org/
|
// Aegisub Project http://www.aegisub.org/
|
||||||
|
|
||||||
/// @file audio_provider_vs.cpp
|
/// @file audio_provider_vs.cpp
|
||||||
/// @brief Vapoursynth-based audio provider
|
/// @brief VapourSynth-based audio provider
|
||||||
/// @ingroup audio_input
|
/// @ingroup audio_input
|
||||||
///
|
///
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
#include "VSScript4.h"
|
#include "VSScript4.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class VapoursynthAudioProvider final : public agi::AudioProvider {
|
class VapourSynthAudioProvider final : public agi::AudioProvider {
|
||||||
VapourSynthWrapper vs;
|
VapourSynthWrapper vs;
|
||||||
VSScript *script = nullptr;
|
VSScript *script = nullptr;
|
||||||
VSNode *node = 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 FillBufferWithFrame(void *buf, int frame, int64_t start, int64_t count) const;
|
||||||
void FillBuffer(void *buf, int64_t start, int64_t count) const override;
|
void FillBuffer(void *buf, int64_t start, int64_t count) const override;
|
||||||
public:
|
public:
|
||||||
VapoursynthAudioProvider(agi::fs::path const& filename);
|
VapourSynthAudioProvider(agi::fs::path const& filename);
|
||||||
~VapoursynthAudioProvider();
|
~VapourSynthAudioProvider();
|
||||||
|
|
||||||
bool NeedsCache() const override { return true; }
|
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<std::mutex> lock(vs.GetMutex());
|
std::lock_guard<std::mutex> lock(vs.GetMutex());
|
||||||
|
|
||||||
VSCleanCache();
|
VSCleanCache();
|
||||||
|
|
||||||
script = vs.GetScriptAPI()->createScript(nullptr);
|
script = vs.GetScriptAPI()->createScript(nullptr);
|
||||||
if (script == nullptr) {
|
if (script == nullptr) {
|
||||||
throw VapoursynthError("Error creating script API");
|
throw VapourSynthError("Error creating script API");
|
||||||
}
|
}
|
||||||
vs.GetScriptAPI()->evalSetWorkingDir(script, 1);
|
vs.GetScriptAPI()->evalSetWorkingDir(script, 1);
|
||||||
if (OpenScriptOrVideo(vs.GetAPI(), vs.GetScriptAPI(), script, filename, OPT_GET("Provider/Audio/VapourSynth/Default Script")->GetString())) {
|
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));
|
std::string msg = agi::format("Error executing VapourSynth script: %s", vs.GetScriptAPI()->getError(script));
|
||||||
vs.GetScriptAPI()->freeScript(script);
|
vs.GetScriptAPI()->freeScript(script);
|
||||||
throw VapoursynthError(msg);
|
throw VapourSynthError(msg);
|
||||||
}
|
}
|
||||||
node = vs.GetScriptAPI()->getOutputNode(script, 0);
|
node = vs.GetScriptAPI()->getOutputNode(script, 0);
|
||||||
if (node == nullptr) {
|
if (node == nullptr) {
|
||||||
vs.GetScriptAPI()->freeScript(script);
|
vs.GetScriptAPI()->freeScript(script);
|
||||||
throw VapoursynthError("No output node set");
|
throw VapourSynthError("No output node set");
|
||||||
}
|
}
|
||||||
if (vs.GetAPI()->getNodeType(node) != mtAudio) {
|
if (vs.GetAPI()->getNodeType(node) != mtAudio) {
|
||||||
vs.GetAPI()->freeNode(node);
|
vs.GetAPI()->freeNode(node);
|
||||||
vs.GetScriptAPI()->freeScript(script);
|
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);
|
vi = vs.GetAPI()->getAudioInfo(node);
|
||||||
float_samples = vi->format.sampleType == stFloat;
|
float_samples = vi->format.sampleType == stFloat;
|
||||||
|
@ -85,10 +85,10 @@ VapoursynthAudioProvider::VapoursynthAudioProvider(agi::fs::path const& filename
|
||||||
channels = vi->format.numChannels;
|
channels = vi->format.numChannels;
|
||||||
num_samples = vi->numSamples;
|
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.
|
// 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
|
// 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<typename T>
|
template<typename T>
|
||||||
|
@ -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];
|
char errorMsg[1024];
|
||||||
const VSFrame *frame = vs.GetAPI()->getFrame(n, node, errorMsg, sizeof(errorMsg));
|
const VSFrame *frame = vs.GetAPI()->getFrame(n, node, errorMsg, sizeof(errorMsg));
|
||||||
if (frame == nullptr) {
|
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) {
|
if (vs.GetAPI()->getFrameLength(frame) < count) {
|
||||||
vs.GetAPI()->freeFrame(frame);
|
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) {
|
if (vs.GetAPI()->getAudioFrameFormat(frame)->numChannels != channels || vs.GetAPI()->getAudioFrameFormat(frame)->bytesPerSample != bytes_per_sample) {
|
||||||
vs.GetAPI()->freeFrame(frame);
|
vs.GetAPI()->freeFrame(frame);
|
||||||
throw VapoursynthError("Audio format is not constant");
|
throw VapourSynthError("Audio format is not constant");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<const uint8_t *> planes(channels);
|
std::vector<const uint8_t *> 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;
|
planes[c] = vs.GetAPI()->getReadPtr(frame, c) + bytes_per_sample * start;
|
||||||
if (planes[c] == nullptr) {
|
if (planes[c] == nullptr) {
|
||||||
vs.GetAPI()->freeFrame(frame);
|
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);
|
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 end = start + count; // exclusive
|
||||||
int startframe = start / VS_AUDIO_FRAME_SAMPLES;
|
int startframe = start / VS_AUDIO_FRAME_SAMPLES;
|
||||||
int endframe = (end - 1) / 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) {
|
if (node != nullptr) {
|
||||||
vs.GetAPI()->freeNode(node);
|
vs.GetAPI()->freeNode(node);
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ VapoursynthAudioProvider::~VapoursynthAudioProvider() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<agi::AudioProvider> CreateVapoursynthAudioProvider(agi::fs::path const& file, agi::BackgroundRunner *) {
|
std::unique_ptr<agi::AudioProvider> CreateVapourSynthAudioProvider(agi::fs::path const& file, agi::BackgroundRunner *) {
|
||||||
return agi::make_unique<VapoursynthAudioProvider>(file);
|
return agi::make_unique<VapourSynthAudioProvider>(file);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
void SetStringVar(const VSAPI *api, VSMap *map, std::string variable, std::string value) {
|
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))
|
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) {
|
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 {
|
} else {
|
||||||
VSMap *map = api->createMap();
|
VSMap *map = api->createMap();
|
||||||
if (map == nullptr)
|
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, "filename", filename.string());
|
||||||
SetStringVar(api, map, "__aegi_vscache", config::path->Decode("?local/vscache").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());
|
SetStringVar(api, map, "__aegi_" + dir, config::path->Decode("?" + dir).string());
|
||||||
|
|
||||||
if (sapi->setVariables(script, map))
|
if (sapi->setVariables(script, map))
|
||||||
throw VapoursynthError("Failed to set script info variables");
|
throw VapourSynthError("Failed to set script info variables");
|
||||||
|
|
||||||
api->freeMap(map);
|
api->freeMap(map);
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
// Aegisub Project http://www.aegisub.org/
|
// Aegisub Project http://www.aegisub.org/
|
||||||
|
|
||||||
/// @file vapoursynth_wrap.cpp
|
/// @file vapoursynth_wrap.cpp
|
||||||
/// @brief Wrapper-layer for Vapoursynth
|
/// @brief Wrapper-layer for VapourSynth
|
||||||
/// @ingroup video_input audio_input
|
/// @ingroup video_input audio_input
|
||||||
///
|
///
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ VapourSynthWrapper::VapourSynthWrapper() {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!hLib)
|
if (!hLib)
|
||||||
throw VapoursynthError("Could not load " VSSCRIPT_SO);
|
throw VapourSynthError("Could not load " VSSCRIPT_SO);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
FUNC* getVSScriptAPI = (FUNC*)GetProcAddress(hLib, "getVSScriptAPI");
|
FUNC* getVSScriptAPI = (FUNC*)GetProcAddress(hLib, "getVSScriptAPI");
|
||||||
|
@ -75,7 +75,7 @@ VapourSynthWrapper::VapourSynthWrapper() {
|
||||||
FUNC* getVSScriptAPI = (FUNC*)dlsym(hLib, "getVSScriptAPI");
|
FUNC* getVSScriptAPI = (FUNC*)dlsym(hLib, "getVSScriptAPI");
|
||||||
#endif
|
#endif
|
||||||
if (!getVSScriptAPI)
|
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
|
// 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
|
// 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());
|
setlocale(LC_ALL, oldlocale.c_str());
|
||||||
|
|
||||||
if (!scriptapi)
|
if (!scriptapi)
|
||||||
throw VapoursynthError("Failed to get Vapoursynth ScriptAPI");
|
throw VapourSynthError("Failed to get VapourSynth ScriptAPI");
|
||||||
|
|
||||||
api = scriptapi->getVSAPI(VAPOURSYNTH_API_VERSION);
|
api = scriptapi->getVSAPI(VAPOURSYNTH_API_VERSION);
|
||||||
|
|
||||||
if (!api)
|
if (!api)
|
||||||
throw VapoursynthError("Failed to get Vapoursynth API");
|
throw VapourSynthError("Failed to get VapourSynth API");
|
||||||
|
|
||||||
vs_loaded = true;
|
vs_loaded = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
#include <libaegisub/exception.h>
|
#include <libaegisub/exception.h>
|
||||||
|
|
||||||
DEFINE_EXCEPTION(VapoursynthError, agi::Exception);
|
DEFINE_EXCEPTION(VapourSynthError, agi::Exception);
|
||||||
|
|
||||||
struct VSAPI;
|
struct VSAPI;
|
||||||
struct VSSCRIPTAPI;
|
struct VSSCRIPTAPI;
|
||||||
|
|
|
@ -30,7 +30,7 @@ std::unique_ptr<VideoProvider> CreateYUV4MPEGVideoProvider(agi::fs::path const&,
|
||||||
std::unique_ptr<VideoProvider> CreateFFmpegSourceVideoProvider(agi::fs::path const&, std::string const&, agi::BackgroundRunner *);
|
std::unique_ptr<VideoProvider> CreateFFmpegSourceVideoProvider(agi::fs::path const&, std::string const&, agi::BackgroundRunner *);
|
||||||
std::unique_ptr<VideoProvider> CreateAvisynthVideoProvider(agi::fs::path const&, std::string const&, agi::BackgroundRunner *);
|
std::unique_ptr<VideoProvider> CreateAvisynthVideoProvider(agi::fs::path const&, std::string const&, agi::BackgroundRunner *);
|
||||||
std::unique_ptr<VideoProvider> CreateBSVideoProvider(agi::fs::path const&, std::string const&, agi::BackgroundRunner *);
|
std::unique_ptr<VideoProvider> CreateBSVideoProvider(agi::fs::path const&, std::string const&, agi::BackgroundRunner *);
|
||||||
std::unique_ptr<VideoProvider> CreateVapoursynthVideoProvider(agi::fs::path const&, std::string const&, agi::BackgroundRunner *);
|
std::unique_ptr<VideoProvider> CreateVapourSynthVideoProvider(agi::fs::path const&, std::string const&, agi::BackgroundRunner *);
|
||||||
|
|
||||||
std::unique_ptr<VideoProvider> CreateCacheVideoProvider(std::unique_ptr<VideoProvider>);
|
std::unique_ptr<VideoProvider> CreateCacheVideoProvider(std::unique_ptr<VideoProvider>);
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ namespace {
|
||||||
{"BestSource", CreateBSVideoProvider, false},
|
{"BestSource", CreateBSVideoProvider, false},
|
||||||
#endif
|
#endif
|
||||||
#ifdef WITH_VAPOURSYNTH
|
#ifdef WITH_VAPOURSYNTH
|
||||||
{"Vapoursynth", CreateVapoursynthVideoProvider, false},
|
{"VapourSynth", CreateVapourSynthVideoProvider, false},
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ static const char *tc_key = "__aegi_timecodes";
|
||||||
static const char *audio_key = "__aegi_hasaudio";
|
static const char *audio_key = "__aegi_hasaudio";
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class VapoursynthVideoProvider: public VideoProvider {
|
class VapourSynthVideoProvider: public VideoProvider {
|
||||||
VapourSynthWrapper vs;
|
VapourSynthWrapper vs;
|
||||||
VSScript *script = nullptr;
|
VSScript *script = nullptr;
|
||||||
VSNode *node = 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);
|
void SetResizeArg(VSMap *args, const VSMap *props, const char *arg_name, const char *prop_name, int64_t deflt, int64_t unspecified = -1);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
VapoursynthVideoProvider(agi::fs::path const& filename, std::string const& colormatrix, agi::BackgroundRunner *br);
|
VapourSynthVideoProvider(agi::fs::path const& filename, std::string const& colormatrix, agi::BackgroundRunner *br);
|
||||||
~VapoursynthVideoProvider();
|
~VapourSynthVideoProvider();
|
||||||
|
|
||||||
void GetFrame(int n, VideoFrame &frame) override;
|
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
|
// 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;
|
int err;
|
||||||
int64_t result = vs.GetAPI()->mapGetInt(props, prop_name, 0, &err);
|
int64_t result = vs.GetAPI()->mapGetInt(props, prop_name, 0, &err);
|
||||||
if (err != 0 || result == unspecified) {
|
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<std::mutex> lock(vs.GetMutex());
|
std::lock_guard<std::mutex> lock(vs.GetMutex());
|
||||||
|
|
||||||
VSCleanCache();
|
VSCleanCache();
|
||||||
|
@ -125,16 +125,16 @@ VapoursynthVideoProvider::VapoursynthVideoProvider(agi::fs::path const& filename
|
||||||
int err1, err2;
|
int err1, err2;
|
||||||
VSCore *core = vs.GetAPI()->createCore(0);
|
VSCore *core = vs.GetAPI()->createCore(0);
|
||||||
if (core == nullptr) {
|
if (core == nullptr) {
|
||||||
throw VapoursynthError("Error creating core");
|
throw VapourSynthError("Error creating core");
|
||||||
}
|
}
|
||||||
script = vs.GetScriptAPI()->createScript(core);
|
script = vs.GetScriptAPI()->createScript(core);
|
||||||
if (script == nullptr) {
|
if (script == nullptr) {
|
||||||
vs.GetAPI()->freeCore(core);
|
vs.GetAPI()->freeCore(core);
|
||||||
throw VapoursynthError("Error creating script API");
|
throw VapourSynthError("Error creating script API");
|
||||||
}
|
}
|
||||||
vs.GetScriptAPI()->evalSetWorkingDir(script, 1);
|
vs.GetScriptAPI()->evalSetWorkingDir(script, 1);
|
||||||
br->Run([&](agi::ProgressSink *ps) {
|
br->Run([&](agi::ProgressSink *ps) {
|
||||||
ps->SetTitle(from_wx(_("Executing Vapoursynth Script")));
|
ps->SetTitle(from_wx(_("Executing VapourSynth Script")));
|
||||||
ps->SetMessage("");
|
ps->SetMessage("");
|
||||||
ps->SetIndeterminate();
|
ps->SetIndeterminate();
|
||||||
|
|
||||||
|
@ -148,20 +148,20 @@ VapoursynthVideoProvider::VapoursynthVideoProvider(agi::fs::path const& filename
|
||||||
});
|
});
|
||||||
if (err1) {
|
if (err1) {
|
||||||
std::string msg = agi::format("Error executing VapourSynth script: %s", vs.GetScriptAPI()->getError(script));
|
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);
|
node = vs.GetScriptAPI()->getOutputNode(script, 0);
|
||||||
if (node == nullptr)
|
if (node == nullptr)
|
||||||
throw VapoursynthError("No output node set");
|
throw VapourSynthError("No output node set");
|
||||||
|
|
||||||
if (vs.GetAPI()->getNodeType(node) != mtVideo) {
|
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);
|
vi = vs.GetAPI()->getVideoInfo(node);
|
||||||
if (vi == nullptr)
|
if (vi == nullptr)
|
||||||
throw VapoursynthError("Couldn't get video info");
|
throw VapourSynthError("Couldn't get video info");
|
||||||
if (!vsh::isConstantVideoFormat(vi))
|
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 fpsNum = vi->fpsNum;
|
||||||
int fpsDen = vi->fpsDen;
|
int fpsDen = vi->fpsDen;
|
||||||
|
@ -174,7 +174,7 @@ VapoursynthVideoProvider::VapoursynthVideoProvider(agi::fs::path const& filename
|
||||||
// Get timecodes and/or keyframes if provided
|
// Get timecodes and/or keyframes if provided
|
||||||
VSMap *clipinfo = vs.GetAPI()->createMap();
|
VSMap *clipinfo = vs.GetAPI()->createMap();
|
||||||
if (clipinfo == nullptr)
|
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, kf_key, clipinfo);
|
||||||
vs.GetScriptAPI()->getVariable(script, tc_key, clipinfo);
|
vs.GetScriptAPI()->getVariable(script, tc_key, clipinfo);
|
||||||
vs.GetScriptAPI()->getVariable(script, audio_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 int64_t *kfs = vs.GetAPI()->mapGetIntArray(clipinfo, kf_key, &err1);
|
||||||
const char *kfs_path = vs.GetAPI()->mapGetData(clipinfo, kf_key, 0, &err2);
|
const char *kfs_path = vs.GetAPI()->mapGetData(clipinfo, kf_key, 0, &err2);
|
||||||
if (err1 && err2)
|
if (err1 && err2)
|
||||||
throw VapoursynthError("Error getting keyframes from returned VSMap");
|
throw VapourSynthError("Error getting keyframes from returned VSMap");
|
||||||
|
|
||||||
if (!err1) {
|
if (!err1) {
|
||||||
keyframes.reserve(numkf);
|
keyframes.reserve(numkf);
|
||||||
|
@ -199,7 +199,7 @@ VapoursynthVideoProvider::VapoursynthVideoProvider(agi::fs::path const& filename
|
||||||
} else {
|
} else {
|
||||||
int kfs_path_size = vs.GetAPI()->mapGetDataSize(clipinfo, kf_key, 0, &err1);
|
int kfs_path_size = vs.GetAPI()->mapGetDataSize(clipinfo, kf_key, 0, &err1);
|
||||||
if (err1)
|
if (err1)
|
||||||
throw VapoursynthError("Error getting size of keyframes path");
|
throw VapourSynthError("Error getting size of keyframes path");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
keyframes = agi::keyframe::Load(config::path->Decode(std::string(kfs_path, size_t(kfs_path_size))));
|
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 int64_t *tcs = vs.GetAPI()->mapGetIntArray(clipinfo, tc_key, &err1);
|
||||||
const char *tcs_path = vs.GetAPI()->mapGetData(clipinfo, tc_key, 0, &err2);
|
const char *tcs_path = vs.GetAPI()->mapGetData(clipinfo, tc_key, 0, &err2);
|
||||||
if (err1 && err2)
|
if (err1 && err2)
|
||||||
throw VapoursynthError("Error getting timecodes from returned map");
|
throw VapourSynthError("Error getting timecodes from returned map");
|
||||||
|
|
||||||
if (!err1) {
|
if (!err1) {
|
||||||
if (numtc != vi->numFrames)
|
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<int> timecodes;
|
std::vector<int> timecodes;
|
||||||
timecodes.reserve(numtc);
|
timecodes.reserve(numtc);
|
||||||
|
@ -228,13 +228,13 @@ VapoursynthVideoProvider::VapoursynthVideoProvider(agi::fs::path const& filename
|
||||||
} else {
|
} else {
|
||||||
int tcs_path_size = vs.GetAPI()->mapGetDataSize(clipinfo, tc_key, 0, &err1);
|
int tcs_path_size = vs.GetAPI()->mapGetDataSize(clipinfo, tc_key, 0, &err1);
|
||||||
if (err1)
|
if (err1)
|
||||||
throw VapoursynthError("Error getting size of keyframes path");
|
throw VapourSynthError("Error getting size of keyframes path");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fps = agi::vfr::Framerate(config::path->Decode(std::string(tcs_path, size_t(tcs_path_size))));
|
fps = agi::vfr::Framerate(config::path->Decode(std::string(tcs_path, size_t(tcs_path_size))));
|
||||||
} catch (agi::Exception const& e) {
|
} catch (agi::Exception const& e) {
|
||||||
// Throw an error here unlike with keyframes since the timecodes not being loaded might not be immediately noticeable
|
// 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);
|
const VSMap *props = vs.GetAPI()->getFramePropertiesRO(frame);
|
||||||
if (props == nullptr)
|
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 sarn = vs.GetAPI()->mapGetInt(props, "_SARNum", 0, &err1);
|
||||||
int64_t sard = vs.GetAPI()->mapGetInt(props, "_SARDen", 0, &err2);
|
int64_t sard = vs.GetAPI()->mapGetInt(props, "_SARDen", 0, &err2);
|
||||||
if (!err1 && !err2) {
|
if (!err1 && !err2) {
|
||||||
|
@ -262,11 +262,11 @@ VapoursynthVideoProvider::VapoursynthVideoProvider(agi::fs::path const& filename
|
||||||
// Convert to RGB24 format
|
// Convert to RGB24 format
|
||||||
VSPlugin *resize = vs.GetAPI()->getPluginByID(VSH_RESIZE_PLUGIN_ID, vs.GetScriptAPI()->getCore(script));
|
VSPlugin *resize = vs.GetAPI()->getPluginByID(VSH_RESIZE_PLUGIN_ID, vs.GetScriptAPI()->getCore(script));
|
||||||
if (resize == nullptr)
|
if (resize == nullptr)
|
||||||
throw VapoursynthError("Couldn't find resize plugin");
|
throw VapourSynthError("Couldn't find resize plugin");
|
||||||
|
|
||||||
VSMap *args = vs.GetAPI()->createMap();
|
VSMap *args = vs.GetAPI()->createMap();
|
||||||
if (args == nullptr)
|
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()->mapSetNode(args, "clip", node, maAppend);
|
||||||
vs.GetAPI()->mapSetInt(args, "format", pfRGB24, maAppend);
|
vs.GetAPI()->mapSetInt(args, "format", pfRGB24, maAppend);
|
||||||
|
@ -299,7 +299,7 @@ VapoursynthVideoProvider::VapoursynthVideoProvider(agi::fs::path const& filename
|
||||||
const VSFrame *rgbframe = GetVSFrame(0);
|
const VSFrame *rgbframe = GetVSFrame(0);
|
||||||
vs.GetAPI()->freeFrame(rgbframe);
|
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)
|
if (node != nullptr)
|
||||||
vs.GetAPI()->freeNode(node);
|
vs.GetAPI()->freeNode(node);
|
||||||
if (script != nullptr)
|
if (script != nullptr)
|
||||||
|
@ -307,27 +307,27 @@ VapoursynthVideoProvider::VapoursynthVideoProvider(agi::fs::path const& filename
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (VapoursynthError const& err) { // for the entire constructor
|
catch (VapourSynthError const& err) { // for the entire constructor
|
||||||
throw VideoProviderError(agi::format("Vapoursynth error: %s", err.GetMessage()));
|
throw VideoProviderError(agi::format("VapourSynth error: %s", err.GetMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
const VSFrame *VapoursynthVideoProvider::GetVSFrame(int n) {
|
const VSFrame *VapourSynthVideoProvider::GetVSFrame(int n) {
|
||||||
char errorMsg[1024];
|
char errorMsg[1024];
|
||||||
const VSFrame *frame = vs.GetAPI()->getFrame(n, node, errorMsg, sizeof(errorMsg));
|
const VSFrame *frame = vs.GetAPI()->getFrame(n, node, errorMsg, sizeof(errorMsg));
|
||||||
if (frame == nullptr) {
|
if (frame == nullptr) {
|
||||||
throw VapoursynthError(agi::format("Error getting frame: %s", errorMsg));
|
throw VapourSynthError(agi::format("Error getting frame: %s", errorMsg));
|
||||||
}
|
}
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VapoursynthVideoProvider::GetFrame(int n, VideoFrame &out) {
|
void VapourSynthVideoProvider::GetFrame(int n, VideoFrame &out) {
|
||||||
std::lock_guard<std::mutex> lock(vs.GetMutex());
|
std::lock_guard<std::mutex> lock(vs.GetMutex());
|
||||||
|
|
||||||
const VSFrame *frame = GetVSFrame(n);
|
const VSFrame *frame = GetVSFrame(n);
|
||||||
|
|
||||||
const VSVideoFormat *format = vs.GetAPI()->getVideoFrameFormat(frame);
|
const VSVideoFormat *format = vs.GetAPI()->getVideoFrameFormat(frame);
|
||||||
if (format->colorFamily != cfRGB || format->numPlanes != 3 || format->bitsPerSample != 8 || format->subSamplingH != 0 || format->subSamplingW != 0) {
|
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);
|
out.width = vs.GetAPI()->getFrameWidth(frame, 0);
|
||||||
|
@ -359,7 +359,7 @@ void VapoursynthVideoProvider::GetFrame(int n, VideoFrame &out) {
|
||||||
vs.GetAPI()->freeFrame(frame);
|
vs.GetAPI()->freeFrame(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
VapoursynthVideoProvider::~VapoursynthVideoProvider() {
|
VapourSynthVideoProvider::~VapourSynthVideoProvider() {
|
||||||
if (node != nullptr) {
|
if (node != nullptr) {
|
||||||
vs.GetAPI()->freeNode(node);
|
vs.GetAPI()->freeNode(node);
|
||||||
}
|
}
|
||||||
|
@ -370,7 +370,7 @@ VapoursynthVideoProvider::~VapoursynthVideoProvider() {
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace agi { class BackgroundRunner; }
|
namespace agi { class BackgroundRunner; }
|
||||||
std::unique_ptr<VideoProvider> CreateVapoursynthVideoProvider(agi::fs::path const& path, std::string const& colormatrix, agi::BackgroundRunner *br) {
|
std::unique_ptr<VideoProvider> CreateVapourSynthVideoProvider(agi::fs::path const& path, std::string const& colormatrix, agi::BackgroundRunner *br) {
|
||||||
return agi::make_unique<VapoursynthVideoProvider>(path, colormatrix, br);
|
return agi::make_unique<VapourSynthVideoProvider>(path, colormatrix, br);
|
||||||
}
|
}
|
||||||
#endif // WITH_VAPOURSYNTH
|
#endif // WITH_VAPOURSYNTH
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
[wrap-git]
|
[wrap-git]
|
||||||
url = https://github.com/Vapoursynth/vapoursynth.git
|
url = https://github.com/vapoursynth/vapoursynth.git
|
||||||
revision = R59
|
revision = R59
|
||||||
patch_directory = vapoursynth
|
patch_directory = vapoursynth
|
||||||
|
|
|
@ -58,7 +58,7 @@ if (!(Test-Path VSFilter)) {
|
||||||
Set-Location $DepsDir
|
Set-Location $DepsDir
|
||||||
}
|
}
|
||||||
|
|
||||||
### Vapoursynth plugins
|
### VapourSynth plugins
|
||||||
|
|
||||||
# L-SMASH-Works
|
# L-SMASH-Works
|
||||||
if (!(Test-Path L-SMASH-Works)) {
|
if (!(Test-Path L-SMASH-Works)) {
|
||||||
|
|
Loading…
Reference in New Issue