diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..24e1ade --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/build +/out +CMakePresets.json +/.vs \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..511d109 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required (VERSION 3.8) + +# Enable Hot Reload for MSVC compilers if supported. +if (POLICY CMP0141) + cmake_policy(SET CMP0141 NEW) + set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$,$>,$<$:EditAndContinue>,$<$:ProgramDatabase>>") +endif() + +project ("vs-misc-tomcup") + +set(VapourSynthSDK "C:/Users/jilig/Downloads/upscale/VapourSynth/sdk") + +add_library(${PROJECT_NAME} SHARED "vs-misc-tomcup.cpp" ) + +add_subdirectory(csv-parser) + +target_include_directories(${PROJECT_NAME} PRIVATE ${VapourSynthSDK}/include csv-parser/include) +target_link_directories(${PROJECT_NAME} PRIVATE ${VapourSynthSDK}/lib64) +target_link_libraries(${PROJECT_NAME} VapourSynth.lib csv) + +set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 20) diff --git a/vs-misc-tomcup.cpp b/vs-misc-tomcup.cpp new file mode 100644 index 0000000..6360a31 --- /dev/null +++ b/vs-misc-tomcup.cpp @@ -0,0 +1,65 @@ +#include "VapourSynth4.h" +#include "VSHelper4.h" +#include +#include +#include "csv.hpp" + +struct SCDetectData { +private: + const VSAPI* vsapi; +public: + VSNode* node; + std::vector scdata; + + explicit SCDetectData(const VSAPI* vsapi) noexcept : vsapi(vsapi) { + + } + + ~SCDetectData() { + vsapi->freeNode(node); + } +}; + + +static const VSFrame* VS_CC filterGetFrame(int n, int activationReason, void* instanceData, void** frameData, VSFrameContext* frameCtx, VSCore* core, const VSAPI* vsapi) { + SCDetectData* d = (SCDetectData*)instanceData; + + if (activationReason == arInitial) { + vsapi->requestFrameFilter(n, d->node, frameCtx); + } + else if (activationReason == arAllFramesReady) { + const VSFrame* frame = vsapi->getFrameFilter(n, d->node, frameCtx); + + /* your code here... */ + + return frame; + } + + return nullptr; +} + +static void VS_CC filterFree(void* instanceData, VSCore* core, const VSAPI* vsapi) { + delete reinterpret_cast(instanceData); +} + +static void VS_CC filterCreate(const VSMap* in, VSMap* out, void* userData, VSCore* core, const VSAPI* vsapi) { + auto data{ std::make_unique(vsapi) }; + + data->node = vsapi->mapGetNode(in, "clip", 0, nullptr); + + csv::CSVReader reader(vsapi->mapGetData(in, "scfile", 0, nullptr)); + for (csv::CSVRow& row : reader) { + data->scdata.push_back(row["Start Frame"].get()); + } + + VSFilterDependency deps[] = { {data->node, rpGeneral} }; /* Depending the the request patterns you may want to change this */ + vsapi->createVideoFilter(out, "SCDetect", vsapi->getVideoInfo(data->node), filterGetFrame, filterFree, fmParallel, deps, 1, data.release(), core); +} + +////////////////////////////////////////// +// Init + +VS_EXTERNAL_API(void) VapourSynthPluginInit2(VSPlugin* plugin, const VSPLUGINAPI* vspapi) { + vspapi->configPlugin("com.tomcup.SCDetect", "misc", "Mark the clip with PySceneDetect's output", VS_MAKE_VERSION(0, 1), VAPOURSYNTH_API_VERSION, 0, plugin); + vspapi->registerFunction("SCDetect", "clip:vnode;scfile:data[]", "clip:vnode;", filterCreate, nullptr, plugin); +} \ No newline at end of file