Log in

View Full Version : Run... the simplest filter I can imagine


mg262
16th June 2005, 10:46
Run (http://people.pwf.cam.ac.uk/mg262/posts/Run.dll)

Brief description: Runs a system command.

Search keywords: run, execute, command line, command prompt, app, application, simple minimal filter.

Full description:
Run(clip, string command) - runs command and returns clip unchanged.

Example:
Blankclip
Run("Echo some text > test.txt")

Notes:
- I should really have made it work without the clip argument... but then I would have had to spend time and space figuring out IClip instead of GenericVideoFilter, and that would defeat the other point, which is:

- The title wasn't entirely tongue in cheek; I thought someone might at some point find really really minimal filter code (W/O any graphics processing) useful when starting to program them... so here it is.

#include "stdafx.h" //includes avisynth.h
#include <stdlib.h>

class Run : public GenericVideoFilter
{
public:
Run(PClip _child, const char *command, IScriptEnvironment *env);
};

Run::Run(PClip _child, const char *command, IScriptEnvironment *env) : GenericVideoFilter(_child)
{
system(command);
}

AVSValue __cdecl Create_FilterName(AVSValue args, void *user_data, IScriptEnvironment *env)
{
return new Run(args[0].AsClip(), args[1].AsString(), env);
}

extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment *env)
{
env->AddFunction("Run", "cs", Create_FilterName, 0);
return "Run plugin";
}

Edit:
After I wrote this I thought of a few more keywords to search for and...
http://forum.doom9.org/showthread.php?t=46506 ('CALL' plug-in.)

Bidoche
16th June 2005, 12:00
You do not have to handle clips to do that.

Just have the run function takes a string, return void, and execute the string as a command when called.

mg262
16th June 2005, 12:45
You do not have to handle clips to do that. That's true... :stupid: Thank you.

But actually where I want it the pass-through is quite convenient. I've never (despite a few searches) been sure whether overloading is legal in AVISynth? I.e.

env->AddFunction("Run", "cs", RunPassThrough, 0);
env->AddFunction("Run", "s", RunDirect, 0);

Edit:
(I know the pass-through can be done with the function as well!)

stickboy
16th June 2005, 18:55
Didn't Nic make a Call plug-in that does this?

mg262
16th June 2005, 18:58
That's what the link at the end of the first post points to... I'll go back and make it clearer.