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 17th November 2013, 15:02   #21  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,018
Quote:
Originally Posted by Forensic View Post
error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
In VC6 New Project, I generally choose Win32 Dynamic-Link Library, with Location
set to my Projects directory and Win32 box ticked. Give it a Project name eg 'Sin'.

I next step, I always select 'An Empty DLL Project' (avoids that stdafx stuff).

In FilesView
Add avisynth.h (and any other of your self made headers) to the Header Files
Add Sin.cpp to the Source Files.

Sin.CPP (From SDK NON-ClipSample)
Code:
#include <windows.h>        // from compiler/SDK include dir
#include <math.h>           // from compiler/SDK include dir
#include "avisynth.h"       // In your project dir

AVSValue Sin(AVSValue args, void* user_data, IScriptEnvironment* env) {
    return sin(args[0].AsFloat());
}

extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* env) {
    env->AddFunction("sin", "f", Sin, 0);
    return "sin";
}
About as simple as it gets.

By The Way, this is how I have my Menu/Tools/Options/Directories set for VS6 + ToolKit 2003 + SDK:

Executable Files:::
C:\Program Files\Microsoft SDK\bin
C:\Program Files\Microsoft Visual C++ Toolkit 2003\bin
C:\Program Files\Microsoft Visual Studio\VC98\BIN
C:\Program Files\Microsoft SDK\bin\winnt
C:\Program Files\Microsoft Visual Studio\COMMON\TOOLS
C:\Program Files\Microsoft Visual Studio\COMMON\MSDev98\Bin
C:\Program Files\Microsoft Visual Studio\COMMON\TOOLS\WINNT
C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
C:\Program Files\Intel\DMIX
C:\WINDOWS\system32\WindowsPowerShell\v1.0
C:\Program Files\Support Tools

Include Files:::
C:\Program Files\Microsoft SDK\include
C:\Program Files\Microsoft Visual C++ Toolkit 2003\include
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE

Library Files:::
C:\Program Files\Microsoft SDK\lib
C:\Program Files\Microsoft Visual C++ Toolkit 2003\lib
C:\Program Files\Microsoft Visual Studio\VC98\LIB
C:\Program Files\Microsoft Visual Studio\VC98\MFC\LIB

Only first 3 files of each section really relevent, I put VC98 entries above Toolkit 2003 normally
(and for debugging as ToolKit 2003 has no debugging), and for final, switch TK2003 above VC98.

Hopefully not too dissimilar to VC2012.

PS, you might find the Avisynth Compiled Help With SDK (CHM) File for v2.6 useful (MediaFire in sig), stick it on a hot-Key.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 20th November 2013 at 18:09.
StainlessS is offline   Reply With Quote
Old 17th November 2013, 16:51   #22  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,433
Quote:
Originally Posted by StainlessS View Post
Avisynth.h is part of your project and should be in same directory as your source files,
included with
Code:
#include "Avisynth.h"
rather than
Code:
#include <Avisynth.h>
which includes from the compiler include paths.
That's not necessary.
Rather than have a copy of avisynth.h in every project source file directory, I prefer just to add the containing folder (eg C:\Program Files\AviSynth 2.5\FilterSDK\include) to the list of include directories for the project. I then use #include <avisynth.h>.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 17th November 2013, 18:00   #23  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,018
Arh but, I frequently use Avisynth.h, Avisynth25.h, Avisynth26.h, and like them when I can get at them easily (and the correct ones) when copying source files for zip.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 20th November 2013, 06:07   #24  |  Link
Forensic
Registered User
 
Join Date: Apr 2008
Location: California, USA
Posts: 127
I am struggling to solve this myself....but...

In VS12, I went to (NEW - Visual C++ Win32 Project - DLL Empty project) and got:



I also tried to get to the finish line with "C:\Program Files\Microsoft Visual Studio\Common\IDE\IDE98\MSE.EXE" but that behaves as just a text editor.

I also have "Visual C++ Toolkit 2003 Command Prompt" but have not yet figured how to use that, if that is the correct solution.
Forensic is offline   Reply With Quote
Old 20th November 2013, 09:46   #25  |  Link
jackoneill
unsigned int
 
jackoneill's Avatar
 
Join Date: Oct 2012
Location: 🇪🇺
Posts: 760
Code:
#include <math.h>
__________________
Buy me a "coffee" and/or hire me to write code!
jackoneill is offline   Reply With Quote
Old 20th November 2013, 09:56   #26  |  Link
JEEB
もこたんインしたお!
 
JEEB's Avatar
 
Join Date: Jan 2008
Location: Finland / Japan
Posts: 512
C/C++ basics, you include and link (if needed) the things you are using from the standard libraries.

Some reference.

Basically include cmath or math.h (the "C++ way" is the first, and the second is the C way -- both should lead to the same result), and the compiler should stop complaining. If the linker complains about not finding the actual implementation, you link the according standard library library.

Also make sure you actually need that windows.h header, don't just include it blindly :P .
__________________
[I'm human, no debug]
JEEB is offline   Reply With Quote
Old 20th November 2013, 11:02   #27  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,433
Quote:
Originally Posted by JEEB View Post
C/C++ basics, you include and link (if needed) the things you are using from the standard libraries.

Some reference.
Also, if you need to use constants like pi, e, etc, in your code, add the following line before including cmath or math.h:
Code:
#define _USE_MATH_DEFINES
See http://msdn.microsoft.com/en-us/library/4hwaceh6.aspx.

In my view, this is better than defining them yourself like JEEB's reference does.
For one thing, it saves you looking up the exact value and possibly mistyping the numbers.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 20th November 2013, 11:31   #28  |  Link
JEEB
もこたんインしたお!
 
JEEB's Avatar
 
Join Date: Jan 2008
Location: Finland / Japan
Posts: 512
Yes, naturally. My intention was to just bring to his knowledge that he should look into how the language and its standard library work in general.
__________________
[I'm human, no debug]
JEEB is offline   Reply With Quote
Old 20th November 2013, 18:07   #29  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,018
Sorry Forensic, my fault, should have included the "#include <math.h>" line.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 20th November 2013, 18:08   #30  |  Link
Forensic
Registered User
 
Join Date: Apr 2008
Location: California, USA
Posts: 127
#define _USE_MATH_DEFINES
#include <math.h>
Adding those two lines eliminated the errors and gave me my first successful AviSynth DLL (now I just have to ask StainlessS how I test his mini-creation). Recompiling other people's valid source code provides a means for me to test how modifications affect the results. That is how I expedited my understanding of AviSynth scripting. I am extremely appreciative of everyone's assistance, and willingness to do so. I realize that my C++ floundering can border on being both comical and a bit pathetic. There are a lot of structural and syntax rules to learn about C++, especially as they relate to building Avisynth 2.58 compliant DLLs. Made tougher by the fact that the last "real" programming languages I used were Cobol, integer basic and 6502 assembly (all from the 1970s). I am incredibly appreciative of everyone's feedback and apologize if my Deer in the headlights comments ever imply anything else. My ONLY goal at this point, is to create useful Avisynth compliant DLLs so I can contribute to my forensic peers and the Doom9 community.
Forensic is offline   Reply With Quote
Old 20th November 2013, 18:11   #31  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,433
Quote:
Originally Posted by JEEB View Post
Yes, naturally. My intention was to just bring to his knowledge that he should look into how the language and its standard library work in general.
I realise that, I was just adding more information to supplement your already helpful post.

However, I'm not so sure about this part:
Quote:
Originally Posted by JEEB View Post
Also make sure you actually need that windows.h header, don't just include it blindly :P .
In my experience, windows.h is always needed before including avisynth.h. Otherwise, you get loads of errors from other windows-related header files that would probably be incomprehensible to a newbie.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 20th November 2013, 18:33   #32  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,018
Nothing wrong with trying out the simplest test dll just to see if the setup works, indeed quite logical.

Code:
colorbars
q=PI/4.0
s= Sin(q)
Subtitle("Sin(" + String(q) + ")" + " = " + String(s))
return last
Now to get to the filter type dll's. (Dont forget to remove dll from plugins)
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 20th November 2013 at 18:49.
StainlessS is offline   Reply With Quote
Old 20th November 2013, 18:44   #33  |  Link
Forensic
Registered User
 
Join Date: Apr 2008
Location: California, USA
Posts: 127
StainlessS, thank you. Now I know that I can successfully compile something (anything) that works!!! Yea. Mission #1 done. Now that my compiler works, back to filters.
Forensic is offline   Reply With Quote
Old 20th November 2013, 19:30   #34  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
Quote:
Originally Posted by Forensic View Post
Now that my compiler works, back to filters.
Next exercise ():
Make a DLL out of this code and figure out what it does:
Code:
#include <windows.h>
#include "avisynth.h"

class Invert : public GenericVideoFilter
{
public:
 Invert(PClip _child) : GenericVideoFilter(_child) {}
 PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
private:
 const BYTE* srcpY;
 const BYTE* srcpU;
 const BYTE* srcpV;
};

AVSValue __cdecl Create_Invert(AVSValue args, void* user_data, IScriptEnvironment* env)
{
 return new Invert(args[0].AsClip());
}

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

PVideoFrame __stdcall Invert::GetFrame(int n, IScriptEnvironment* env)
{
 PVideoFrame src = child->GetFrame(n, env);
 PVideoFrame dst = env->NewVideoFrame(vi);

 srcpY = src->GetReadPtr(PLANAR_Y);
 srcpU = src->GetReadPtr(PLANAR_U);
 srcpV = src->GetReadPtr(PLANAR_V);

 BYTE* dstpY = dst->GetWritePtr(PLANAR_Y);
 BYTE* dstpU = dst->GetWritePtr(PLANAR_U);
 BYTE* dstpV = dst->GetWritePtr(PLANAR_V);

 const int src_pitchY = src->GetPitch(PLANAR_Y);
 const int src_pitchUV = src->GetPitch(PLANAR_V);
 const int dst_pitchY = dst->GetPitch(PLANAR_Y);
 const int dst_pitchUV = dst->GetPitch(PLANAR_U);

 const int row_sizeY = dst->GetRowSize(PLANAR_Y);
 const int row_sizeUV = dst->GetRowSize(PLANAR_U);

 const int heightY = dst->GetHeight(PLANAR_Y);
 const int heightUV = dst->GetHeight(PLANAR_U);

 int y, x;

 for (y = 0; y < heightY; y++)
 {
  for (int x = 0; x < row_sizeY; x++)
   dstpY[x] = srcpY[x] ^ 0xFF;

  srcpY += src_pitchY;
  dstpY += dst_pitchY;
 }

 for (y = 0; y < heightUV; y++)
 {
  for (int x = 0; x < row_sizeUV; x++)
  {
   dstpU[x] = srcpU[x] ^ 0xFF;
   dstpV[x] = srcpV[x] ^ 0xFF;
  }

  srcpU += src_pitchUV;
  dstpU += dst_pitchUV;
  srcpV += src_pitchUV;
  dstpV += dst_pitchUV;
 }

 return dst;
}
Groucho2004 is offline   Reply With Quote
Old 20th November 2013, 19:59   #35  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,433
Quote:
Originally Posted by Groucho2004 View Post
Make a DLL out of this code and figure out what it does
For bonus points, explain why it is not thread-safe, and how that can be fixed.
Hint:
Code:
class Invert : public GenericVideoFilter
{
 ...
 const BYTE* srcpY;
 const BYTE* srcpU;
 const BYTE* srcpV;
};
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 20th November 2013, 20:55   #36  |  Link
Forensic
Registered User
 
Join Date: Apr 2008
Location: California, USA
Posts: 127
Groucho2004. That is so awesome that you are doing this for me. Hopefully, all of the newbies will benefit from this too. Compiling and loading the DLL was easy enough and my best guess of your code is that it shifts the U&V pixel values in a linear fashion with each successive frame. The part stumping me is the function call. Reading your code, I thought the call (using colorbars for the test) was colorbars.PVideoFrame or colorbars.Invert
The first one fails to be recognized and the second is an internal call. So I admit my stupidity....what is the function call?
Forensic is offline   Reply With Quote
Old 20th November 2013, 21:34   #37  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,018
Argument is clip only, source clip Planar, Colorbars().ConvertToYV12().Invert(),
dont forget to copy dll to plugins, else will use built-in Invert().
Remove dll afterwards.

Below tells avisynth about the plugin name and args.
Code:
extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* env)
{
 env->AddFunction("Invert", "c", Create_Invert, 0);
 return "Invert plugin";
}
This is (TwoFiveInvert) sample from SDK. http://avisynth.nl/index.php/Filter_SDK
also in Avisynth 2.6 + SDK compressed helpfile as previously posted (MediaFire in sig).
EDIT: Not TwoFiveInvert, but very similar.

EDIT: This is the bit that does invert (on Y)
Code:
dstpY[x] = srcpY[x] ^ 0xFF;
the '^' is XOR, XOR with $FF makes eg 0->FF and FF->0. (Copying from source, XOR, to Dest)

To call another built-in or external function (you need to know it exists) see Invoke. http://avisynth.nl/index.php/Cplusplus_API
(Most filters do the hard work themselves and do not call built-in/external filters)
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 20th November 2013 at 21:55.
StainlessS is offline   Reply With Quote
Old 20th November 2013, 22:10   #38  |  Link
Forensic
Registered User
 
Join Date: Apr 2008
Location: California, USA
Posts: 127
I did not realize the DLL worked because its functionality was indistinguishable fromo the internal "Invert" function. So...I recompiled it after changing all instances of "Invert" to "InvertX", just to be sure, and everything worked. Best of all, everything is being done in VC++ 2012 Express. I will now manipulate this code, and other plug-in source codes, along with reading two very large C++ books. As for Gavino's bonus question on thread-safe coding; my best guess is that the noted constants are being defined as public variable that potentially conflict with other functions wanting to load, or overload, the same variable names. But that is just my instinctual guess...not from understanding C++.
Forensic is offline   Reply With Quote
Old 20th November 2013, 22:12   #39  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,018
Methinks that the Gavino Bonus Points were aimed at Grouchy.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 20th November 2013, 22:29   #40  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
Quote:
Originally Posted by Gavino View Post
For bonus points, explain why it is not thread-safe, and how that can be fixed.
Hint:
Code:
class Invert : public GenericVideoFilter
{
 ...
 const BYTE* srcpY;
 const BYTE* srcpU;
 const BYTE* srcpV;
};
Damn, didn't realize that was still there. I was playing around with this a long time ago. I should really look at the code before posting...
Yes, these 3 const BYTE* should be local in ::GetFrame() just as the "BYTE* dstp" vars.
Groucho2004 is offline   Reply With Quote
Reply

Tags
avisynth, c++, compile, dll

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 16:45.


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