Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
6th June 2016, 03:10 | #1 | Link |
Registered User
Join Date: Nov 2009
Posts: 327
|
C++ API for VapourSynth
Do you miss the AviSynth plugin API? Can't remember the signatures for all those VSAPI plugin callbacks? Dealing with optional filter arguments got you down? Memory leaks driving you crazy? Try VapourSynth++.
Consider the SDK invert example with VS++: Code:
#include <stdexcept> #include "vsxx_pluginmain.h" using namespace vsxx; class InvertFilter : public FilterBase { FilterNode m_node; VSVideoInfo m_vi; bool m_enabled; public: InvertFilter(void * = nullptr) : m_vi(), m_enabled{} {} const char *get_name(int) noexcept override { return "Invert"; } std::pair<VSFilterMode, int> init(const ConstPropertyMap &in, const PropertyMap &out, const VapourCore &core) { m_node = in.get_prop<FilterNode>("clip"); m_vi = m_node.video_info(); m_enabled = in.get_prop<bool>("enabled", map::default_val(true)); if (!m_vi.format || m_vi.format->sampleType != stInteger || m_vi.format->bitsPerSample != 8) throw std::runtime_error{ "clip must be 8-bit integer" }; return{ fmParallel, 0 }; } std::pair<const VSVideoInfo *, size_t> get_video_info() noexcept override { return{ &m_vi, 1 }; } void get_frame_initial(int n, const VapourCore &, VSFrameContext *frame_ctx) override { m_node.request_frame_filter(n, frame_ctx); } ConstVideoFrame get_frame(int n, const VapourCore &core, VSFrameContext *frame_ctx) override { ConstVideoFrame src = m_node.get_frame_filter(n, frame_ctx); if (!m_enabled) return src; const VSFormat &format = src.format(); VideoFrame dst = core.new_video_frame(format, src.width(0), src.height(0)); for (int p = 0; p < format.numPlanes; ++p) { const uint8_t *src_p = src.read_ptr(p); uint8_t *dst_p = dst.write_ptr(p); int src_stride = src.stride(p); int dst_stride = dst.stride(p); int w = src.width(p); int h = src.height(p); for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { dst_p[j] = ~src_p[j]; } src_p += src_stride; dst_p += dst_stride; } } return dst; } }; const PluginInfo g_plugin_info = { "com.example.invert", "invert", "VapourSynth Invert Example", { { &FilterBase::filter_create<InvertFilter>, "Invert", "clip:clip;enabled:int:opt;" } } }; Download: CatHub Last edited by Stephen R. Savage; 6th June 2016 at 18:42. |
6th June 2016, 13:41 | #3 | Link |
Beyond Kawaii
Join Date: Feb 2008
Location: Russia
Posts: 724
|
Bad idea. There are many compilers with different ABI. Plugins written in C++ with such an API may or may not be compatible with VapourSynth, depending on which compiler they were compiled with.
__________________
...desu! Last edited by Mystery Keeper; 6th June 2016 at 14:07. |
6th June 2016, 14:51 | #4 | Link | |
Registered User
Join Date: Oct 2010
Posts: 36
|
Quote:
This is different to the AviSynth C++ API where it doesn't wrap around a C interface and as such has ABI issues due to C++ class mangling making linking between different compilers impossible. |
|
6th June 2016, 19:56 | #5 | Link | |
Beyond Kawaii
Join Date: Feb 2008
Location: Russia
Posts: 724
|
Quote:
__________________
...desu! |
|
7th June 2016, 08:48 | #6 | Link | |
Registered User
Join Date: Oct 2010
Posts: 36
|
Quote:
Yes, or use one that someone else has written. This is no different to using the c++ interface for other APIs like OpenCL or JNI. They're designed to provide a better interface that's more aligned to C++ coding style and should take advantage of the features that c++ uses that C doesn't. I haven't spent much time reading this wrapper, but for a first pass it looks reasonably sane. |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|