Skip to content

Commit

Permalink
Migrate to VS API4
Browse files Browse the repository at this point in the history
  • Loading branch information
HolyWu committed Oct 4, 2021
1 parent 35ecaca commit 8af45b8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ If you want to put ffms2's index file at another place rather than the same dire
mpls = core.mpls.Read(r'D:\Downloads\rule6', 0)
clips = []
for i in range(mpls['count']):
clips.append(core.ffms2.Source(source=mpls['clip'][i], cachefile=r'D:\indices\rule6\' + mpls['filename'][i].decode() + '.ffindex'))
clips.append(core.ffms2.Source(source=mpls['clip'][i], cachefile=r'D:\indices\rule6\' + mpls['filename'][i] + '.ffindex'))
clip = core.std.Splice(clips)
```

Expand Down
41 changes: 22 additions & 19 deletions ReadMpls/ReadMpls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

#include <string>

#include <VapourSynth.h>
#include <VSHelper.h>
#include <VapourSynth4.h>
#include <VSHelper4.h>

#include <libbluray/bluray.h>

Expand All @@ -27,30 +27,30 @@ using namespace std::literals;
static void VS_CC readMplsCreate(const VSMap* in, VSMap* out, [[maybe_unused]] void* userData, [[maybe_unused]] VSCore* core, const VSAPI* vsapi) {
auto err{ 0 };

auto bd_path{ vsapi->propGetData(in, "bd_path", 0, nullptr) };
auto playlist{ int64ToIntS(vsapi->propGetInt(in, "playlist", 0, nullptr)) };
auto angle{ int64ToIntS(vsapi->propGetInt(in, "angle", 0, &err)) };
auto bd_path{ vsapi->mapGetData(in, "bd_path", 0, nullptr) };
auto playlist{ vsapi->mapGetIntSaturated(in, "playlist", 0, nullptr) };
auto angle{ vsapi->mapGetIntSaturated(in, "angle", 0, &err) };

auto bd{ bd_open(bd_path, nullptr) };
if (!bd)
return vsapi->setError(out, ("ReadMpls: failed to open "s + bd_path).c_str());
return vsapi->mapSetError(out, ("ReadMpls: failed to open "s + bd_path).c_str());

auto titleInfo{ bd_get_playlist_info(bd, playlist, angle) };
if (!titleInfo) {
vsapi->setError(out, "ReadMpls: failed to get information of the specified playlist or angle");
vsapi->mapSetError(out, "ReadMpls: failed to get information of the specified playlist or angle");
bd_close(bd);
return;
}

vsapi->propSetInt(out, "count", titleInfo->clip_count, paReplace);
vsapi->mapSetInt(out, "count", titleInfo->clip_count, maReplace);
for (auto i{ 0U }; i < titleInfo->clip_count; i++) {
auto filename{ titleInfo->clips[i].clip_id + ".m2ts"s };
vsapi->propSetData(out, "clip", (bd_path + "/BDMV/STREAM/"s + filename).c_str(), -1, paAppend);
vsapi->propSetData(out, "filename", filename.c_str(), -1, paAppend);
vsapi->mapSetData(out, "clip", (bd_path + "/BDMV/STREAM/"s + filename).c_str(), -1, dtUtf8, maAppend);
vsapi->mapSetData(out, "filename", filename.c_str(), -1, dtUtf8, maAppend);
}
if (titleInfo->clip_count == 1) {
vsapi->propSetData(out, "clip", "", -1, paAppend);
vsapi->propSetData(out, "filename", "", -1, paAppend);
vsapi->mapSetData(out, "clip", "", -1, dtUtf8, maAppend);
vsapi->mapSetData(out, "filename", "", -1, dtUtf8, maAppend);
}

bd_free_title_info(titleInfo);
Expand All @@ -60,11 +60,14 @@ static void VS_CC readMplsCreate(const VSMap* in, VSMap* out, [[maybe_unused]] v
//////////////////////////////////////////
// Init

VS_EXTERNAL_API(void) VapourSynthPluginInit(VSConfigPlugin configFunc, VSRegisterFunction registerFunc, VSPlugin* plugin) {
configFunc("com.holywu.readmpls", "mpls", "Get m2ts clip id from a playlist and return a dict", VAPOURSYNTH_API_VERSION, 1, plugin);
registerFunc("Read",
"bd_path:data;"
"playlist:int;"
"angle:int:opt;",
readMplsCreate, nullptr, plugin);
VS_EXTERNAL_API(void) VapourSynthPluginInit2(VSPlugin* plugin, const VSPLUGINAPI* vspapi) {
vspapi->configPlugin("com.holywu.readmpls", "mpls", "Get m2ts clip id from a playlist and return a dict", VS_MAKE_VERSION(4, 0), VAPOURSYNTH_API_VERSION, 0, plugin);
vspapi->registerFunction("Read",
"bd_path:data;"
"playlist:int;"
"angle:int:opt;",
"count:int;"
"clip:data;"
"filename:data;",
readMplsCreate, nullptr, plugin);
}
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project('ReadMpls', 'cpp',
version: '4'
)

vapoursynth_dep = dependency('vapoursynth').partial_dependency(compile_args: true, includes: true)
vapoursynth_dep = dependency('vapoursynth', version: '>=55').partial_dependency(compile_args: true, includes: true)

libbluray_dep = dependency('libbluray')

Expand Down

0 comments on commit 8af45b8

Please sign in to comment.