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

Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
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++:

#include <stdexcept>
#include "vsxx_pluginmain.h"

using namespace vsxx;

class InvertFilter : public FilterBase {
	FilterNode m_node;
	VSVideoInfo m_vi;
	bool m_enabled;
	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

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 10:24.

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