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.

 

Go Back   Doom9's Forum > Capturing and Editing Video > VapourSynth

Reply
 
Thread Tools Search this Thread Display Modes
Old 6th June 2016, 03:10   #1  |  Link
Stephen R. Savage
Registered User
 
Stephen R. Savage's Avatar
 
Join Date: Nov 2009
Posts: 345
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;" }
	}
};
VS++ eliminates boilerplate and lets you focus on your algorithm.

Download: CatHub

Last edited by Stephen R. Savage; 6th June 2016 at 18:42.
Stephen R. Savage is offline   Reply With Quote
Old 6th June 2016, 10:28   #2  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: Providence, RI
Posts: 2,376
New fancy toy, gr8
__________________
If I got new ideas, will post here: https://github.com/IFeelBloated
feisty2 is offline   Reply With Quote
Old 6th June 2016, 13:41   #3  |  Link
Mystery Keeper
Beyond Kawaii
 
Mystery Keeper's Avatar
 
Join Date: Feb 2008
Location: Russia
Posts: 717
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.
Mystery Keeper is offline   Reply With Quote
Old 6th June 2016, 14:51   #4  |  Link
splinter98
Registered User
 
Join Date: Oct 2010
Posts: 36
Quote:
Originally Posted by Mystery Keeper View Post
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.
Surely that doesn't apply here as the C++ header here is actually a wrapper around the C interface, so the C++ is self contained to the module.

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.
splinter98 is offline   Reply With Quote
Old 6th June 2016, 19:56   #5  |  Link
Mystery Keeper
Beyond Kawaii
 
Mystery Keeper's Avatar
 
Join Date: Feb 2008
Location: Russia
Posts: 717
Quote:
Originally Posted by splinter98 View Post
Surely that doesn't apply here as the C++ header here is actually a wrapper around the C interface, so the C++ is self contained to the module.

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.
Ah, okay. But that's all up to coders. Anyone who feels the need can write their wrapper.
__________________
...desu!
Mystery Keeper is offline   Reply With Quote
Old 7th June 2016, 08:48   #6  |  Link
splinter98
Registered User
 
Join Date: Oct 2010
Posts: 36
Quote:
Originally Posted by Mystery Keeper View Post
Ah, okay. But that's all up to coders. Anyone who feels the need can write their wrapper.


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.
splinter98 is offline   Reply With Quote
Old 6th June 2020, 18:01   #7  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: Providence, RI
Posts: 2,376
has the name "vs++" been offically taken by this wrapper? the only name reference in its repository seems to be "vsxx"

I will take the name "vs++" for my wrapper if it is still available
__________________
If I got new ideas, will post here: https://github.com/IFeelBloated
feisty2 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:44.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.