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 > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 30th September 2007, 03:54   #1  |  Link
ShinSan
Registered User
 
Join Date: Oct 2004
Posts: 19
Do you even need to copy to make an avisynth plugin?

Well, I was wondering about making a few "filters" for avisynth that actually have nothing to do with filtering. Kind-of a "null" filter, but I want to do things like processing other files in preparation for a filter (like generate an image file for use as an overlay). What's nice about avisynth is that it's a scripting language, and it could make things convenient if I want to pass the script to another person.

So far, from what I gathered from the SDK and the sample filter code, I haven't seen any complete sets of code that had anything less than a copy snippet. Is there a way to just bypass that completely?
ShinSan is offline   Reply With Quote
Old 30th September 2007, 07:06   #2  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
You can look at some of my plug-ins, most of which don't do any image processing.
stickboy is offline   Reply With Quote
Old 30th September 2007, 09:35   #3  |  Link
Leak
ffdshow/AviSynth wrangler
 
Leak's Avatar
 
Join Date: Feb 2003
Location: Austria
Posts: 2,441
Quote:
Originally Posted by ShinSan View Post
So far, from what I gathered from the SDK and the sample filter code, I haven't seen any complete sets of code that had anything less than a copy snippet. Is there a way to just bypass that completely?
You could do what you want to do when your plugin's constructor is called, then simply make GetFrame call the parent filter's GetFrame and pass the frame through. That has about as little overhead as possible...

np: Burnt Friedman - Chaos Breeds 1 (First Night Forever)
__________________
now playing: [artist] - [track] ([album])

Last edited by Leak; 30th September 2007 at 09:38.
Leak is offline   Reply With Quote
Old 30th September 2007, 17:34   #4  |  Link
ShinSan
Registered User
 
Join Date: Oct 2004
Posts: 19
Yeah, I thought of just passing the source pointer out 10 mins after I made that forum post. Still, stickboy's examples will come in really handy for me.
ShinSan is offline   Reply With Quote
Old 30th September 2007, 22:30   #5  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
The lowest overhead is to just return the input PClip in the creator proceedure (the routine you registered with AddFunction), this way no filter object is added to the graph.

To run code at the end of the script, you register an AtExit proceedure.
IanB is offline   Reply With Quote
Old 30th September 2007, 23:02   #6  |  Link
ShinSan
Registered User
 
Join Date: Oct 2004
Posts: 19
Quote:
Originally Posted by IanB View Post
To run code at the end of the script, you register an AtExit proceedure.
You read my mind. I was actually wondering about that aspect.
ShinSan is offline   Reply With Quote
Old 1st October 2007, 03:55   #7  |  Link
ShinSan
Registered User
 
Join Date: Oct 2004
Posts: 19
Okay, I've got the basic filter to compile and work, but can someone show me an example on how to write an AtExit function? I tried searching the filter SDK and forum but couldn't find much.

Last edited by ShinSan; 1st October 2007 at 04:00.
ShinSan is offline   Reply With Quote
Old 1st October 2007, 14:36   #8  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
From Avisynth.h
Code:
  typedef AVSValue (__cdecl *ApplyFunc)(AVSValue args, void* user_data, IScriptEnvironment* env);

  virtual void __stdcall AddFunction(const char* name, const char* params, ApplyFunc apply, void* user_data) = 0;

...

  typedef void (__cdecl *ShutdownFunc)(void* user_data, IScriptEnvironment* env);

  virtual void __stdcall AtExit(ShutdownFunc function, void* user_data) = 0;
Like when you register a creator ApplyFunc with env->AddFunction, you similarly register a ShutdownFunc with env->AtExit.

When IScriptEnvironment is deleted on script close the AtExit functions get run. When you register the func you can optionally provide some user data. When the function is finally called this data will be provided as the argument to the proceedure. Be carefull not to pass pointers to Avisynth manage objects, because they most likely will have been deleted before the AtExit functions are called.
Code:
// Declare a proceedure
void __cdecl AtExitProc(void* user_data, IScriptEnvironment* env) {
// Do stuff!
...
  return;
}
...
  env->AtExit(AtExitProc, 0); // Register shutdown proc for 'ron
...
IanB is offline   Reply With Quote
Old 1st October 2007, 16:13   #9  |  Link
ShinSan
Registered User
 
Join Date: Oct 2004
Posts: 19
Thanks. Got the function to work correctly but looks like it might not work in my case due to weird Win32API quirks. I have other ways around it though.

Last edited by ShinSan; 1st October 2007 at 16:15.
ShinSan is offline   Reply With Quote
Old 1st October 2007, 16:29   #10  |  Link
Ebobtron
Errant Knight
 
Ebobtron's Avatar
 
Join Date: Oct 2004
Location: St Louis, M0 US
Posts: 364
Quote:
weird Win32API quirks.
There are many, which are giving you fits.
??

Last edited by Ebobtron; 1st October 2007 at 16:33.
Ebobtron is offline   Reply With Quote
Old 3rd October 2007, 04:39   #11  |  Link
ShinSan
Registered User
 
Join Date: Oct 2004
Posts: 19
Well, basically I'm trying to rig a "filter" that will load fonts, but loads them so that they are gone on a reboot using AddFontResource. I put RemoveFontResource on the atexitproc, but I think what's happening is that when I close the file using virtualdub, the video is still kinda loaded and in the process of being closed when the filter closes, so I'll probably write a separate program to handle the font removal using something like a text file written to disc containing the font information. Main reason is that the primary Windows font directory can get clogged with font files and affect the OS.

It's designed to be used in conjunction with a filter like vsfilter.

One thing I think I'll do is to simplify the current filter since most of the functionality can probably be done with only those two functions. Right now the function is rigged so that it takes all of the fonts in a directory (except the adobe type1s) and loads them automatically.

Last edited by ShinSan; 3rd October 2007 at 05:27.
ShinSan is offline   Reply With Quote
Old 3rd October 2007, 05:01   #12  |  Link
ShinSan
Registered User
 
Join Date: Oct 2004
Posts: 19
Here's what I have, as an attachment. I put in a bunch of MessageBox codes to help figure out return values. I took out the extra fluff code (the directory processing) to try to tackle the RemoveFontResource/AtExit problem first.

To be honest, having the font removed from the system on reboot (thanks to AddFontResource) is basically all I wanted to accomplish, but of course being able to automatically unload the font without the reboot would be nice icing on the cake.
Attached Files
File Type: txt main.cpp.txt (2.8 KB, 48 views)

Last edited by ShinSan; 4th October 2007 at 04:44.
ShinSan is offline   Reply With Quote
Old 25th November 2007, 11:36   #13  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Code:
/* LoadFont for avisynth
   
   Created by Shin-san of Ishin Digital Anime Fansubbing
   Special thanks to stickboy, Leak, and IanB of the doom9.org forums for the help
   Special thanks to sh0dan for his simple sample script, which this file is based on

   This code, if made public, is protected by the GPLv3, which can be found at
   www.gnu.org. I'm too lazy to copy/paste it in here

   Purpose: to make it so I can load a font into Windows and automatically unload it 
   after avisynth is done running
*/

#include <windows.h>
#include "avisynth.h"

void __cdecl UnLoadFont(void* user_data, IScriptEnvironment* env);

AVSValue __cdecl Create_LoadFont(AVSValue args, void* user_data, IScriptEnvironment* env) {

   char *file = args[1].AsString("");

   // and now load the font
   if ( (AddFontResource( file )) > 0 )
   {
      MessageBox(NULL, "LOADED", file, MB_OK);

      SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);

      env->AtExit(UnLoadFont, strdup(file) );
   }
   else
   {
      env->ThrowError("LoadFont: Font load '%s' failed.", file);
   }
   return args[0];
}

extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* env)
{
    env->AddFunction("LoadFont", "c[FONT]s", Create_LoadFont, 0);

    return "'LoadFont' LoadFont plugin";
    // A freeform name of the plugin.
}

void __cdecl UnLoadFont(void* user_data, IScriptEnvironment* env)
{
   char *loadedFont = (char*)user_data;

   if (loadedFont && *loadedFont)
   {
      if ( RemoveFontResource(loadedFont) > 0 )
      {
         MessageBox(NULL, "UNLOADED", loadedFont, MB_OK);
         SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
      }
      else
      {
         MessageBox(NULL, "NOT UNLOADED", loadedFont, MB_OK);
      }
      free(loadedFont);
   }
   else
   {
      MessageBox(NULL, "er...", loadedFont, MB_OK);
   }
   return;
}
IanB is offline   Reply With Quote
Old 25th November 2007, 11:59   #14  |  Link
Adub
Fighting spam with a fish
 
Adub's Avatar
 
Join Date: Sep 2005
Posts: 2,699
Fansubbing?
__________________
FAQs:Bond's AVC/H.264 FAQ
Site:Adubvideo
Adub is offline   Reply With Quote
Old 25th November 2007, 13:22   #15  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Yes

Deleting code to make it even better



@Fizick,

If you nuke all the MessageBox crap it could make another reasonable example for your SDK pages.
IanB is offline   Reply With Quote
Old 25th November 2007, 14:09   #16  |  Link
Fizick
AviSynth plugger
 
Fizick's Avatar
 
Join Date: Nov 2003
Location: Russia
Posts: 2,183
Done.
Fizick 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 12:49.


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