Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcup committed Jul 21, 2023
1 parent 45e3a8a commit cd62ad0
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/build
/out
CMakePresets.json
/.vs
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>: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)
65 changes: 65 additions & 0 deletions vs-misc-tomcup.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "VapourSynth4.h"
#include "VSHelper4.h"
#include <memory>
#include <vector>
#include "csv.hpp"

struct SCDetectData {
private:
const VSAPI* vsapi;
public:
VSNode* node;
std::vector<int> 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<SCDetectData*>(instanceData);
}

static void VS_CC filterCreate(const VSMap* in, VSMap* out, void* userData, VSCore* core, const VSAPI* vsapi) {
auto data{ std::make_unique<SCDetectData>(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<int>());
}

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);
}

0 comments on commit cd62ad0

Please sign in to comment.