Log in

View Full Version : AVS In VisualBasic .NET


OvejaNegra
12th May 2006, 04:46
I´m working in a small application for Avs Scripts creation.
Since i´m working with visual basic 2005 i need some help
with the following:

How can i import avisynth dll functions to read a script and put
the frames to a preview window (like in megui o GK)
i was reading the megui source but i dont speak c# (or c++, sorry)

I think the script is opened using avs_create_script_environment,
but then the frames are converted to BMP (why?).


How can i do this?
Can anybody give me an example?

Thanks for the help and sorry for my english.

stax76
12th May 2006, 08:50
Ever heard of DVX or StaxRip? It's a GK alternative since 5 years... Might this be what you are looking for?

unmei
12th May 2006, 12:36
but then the frames are converted to BMP (why?).

If you want to display the frames in a preview or such you "cannot" display them in a YUV colorspace. Well, you could reinterpret Y as R, U as G and V as B but that is most likely not what the user is interested in seeing.
If you referred to why the frame object is converted to a Bitmap object, many languages use Bitmap or similarly named classes for pictures when you want to display them onscreen. Its is just kind of language standardized container for the raw data (pixels). Converting the frame to Bitmap and assigning them to a Graphics object on screen is one method, another would be to keep the same Bitmap instance displayed to the user but copying data from every new frame "pixel by pixel" into that Bitmap's memory area.

Inc
12th May 2006, 13:41
http://forum.doom9.org/showthread.php?p=800030#post800030

The dll is accessed using stdcall, so it should be full useful for VB.
Look in the also provided PureBasic Dll sample code. As its basic, well .. ;) ... translating to VB should be no problem.
If you get a frame by the dlls function I integrated a routine where it gets already converted to rgb32 and allocated to a bitmap-image. So get the frame in VB and allocate/update it to a given Imageframe. So no Win-API needed like GetDC(), SetDiBits() etc.

OvejaNegra
15th May 2006, 07:11
stax: YES i know StaxRip, it´s one of the tools i´m studying for
my iENCODER (a batch encoding tool) but i´m doing my own tool just for fun and learning and (of course) ego-satisfaction. Thanks!

unmei: oh!! i see!! Yes you are right!!!! and thats most suitable for res and cropping!!! Thanks!!!

INC: JUST WHAT I NEED!!! THNKS A LOT!!! i really dON´t want use win-api calls, THANKS!!!!!

Sorry for my english (Again) ;-)

Inc
15th May 2006, 08:46
Sorry for my english (Again)
no más peor que mi español ;)

OvejaNegra
15th May 2006, 19:57
INC: Don´t worry, i do not speak german either!!!

OvejaNegra
7th June 2006, 06:07
OK ok, since 3 weeks, i have time again to play with VB, but now i´m having problems again
Can anybody tell me why this code is not working?
PLEASE!! I´m NOT programmer ok!! if you see something stupid here DON´T use words to insult me, use ******* it´s more fun.

OK the code:
Public Class Form1
Public Declare Auto Function avs_create Lib "avsredirect.dll" Alias "_avs_create@0" () As Long
Public Declare Auto Function avs_open Lib "avsredirect.dll" Alias "_avs_open@12" (ByVal env As Long, ByVal fname As String, ByRef vi As AVSDLLVideoInfo) As Integer

Structure AVSDLLVideoInfo
'Video
Dim width As Long
Dim height As Long
Dim raten As Long
Dim rated As Long
Dim aspectn As Long
Dim aspectd As Long
Dim interlaced_frame As Long
Dim top_field_first As Long
Dim num_frames As Long
Dim pixel_type As Long
'Audio
Dim audio_samples_per_second As Long
Dim sample_type As Long
Dim nChannels As Long
Dim num_audio_frames As Long
Dim num_audio_samples As Double

End Structure

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myenv As Long = 0
Dim clip As Integer = 0
Dim myvi As AVSDLLVideoInfo
myenv = avs_create
clip = avs_open(myenv, "c:\test.avs", myvi)


End Sub
End Class


after runnig this, all the variables still empty :-(

Sorry for all this!!!
Thanks!!

Inc
7th June 2006, 20:46
My skill on VB are near ZERO, so sorry :(

The last release posted in the thread I linked to (just imho) already gots the symbols using the following names ...
(look at the provided PureBasic code and you see whats used)

avs_init
avs_exit
avs_close
avs_create_env
avs_destroy_env
avs_getaframe
avs_getlasterror
avs_getlasterror_CRLF
avs_getvframe
avs_open_file
avs_open_script

1. For initialization get the path to the folder which containins the dll:
avs_init("C:\ThePathTo\TheFolderOfTheAvsRedirectDll\" )

2. Create a scriptenvironment:
env = avs_create_env()

3. Check if no Avisynth Error happend
If avs_getlasterror_CRLF(@error.s, 1024)
MessageRequester("Avisynth failure!", error)
Endif

4. Get the clip ...
clip = avs_open(env, @avsfile, @vi.AVSDLLVideoInfo, #True)Im not shure if the version you got as las parameter uses #True which means a RGB32 output. So try as last parameter (also to be set in the declaration) True

5. Again check if no Avisynth Error happend
If avs_getlasterror_CRLF(@error.s, 1024)
MessageRequester("Avisynth failure!", error)
Endif

@avsfile.s = the pointer! to the String
@vi.AVSDLLVideoInfo = the pointer! to vi declared as AVSDllVideoInfo Structure

OvejaNegra
13th June 2006, 22:52
OK:
First of all: INC: Sorry for taking too long for respond.
Second: Now I´m allmost there thanks to your answer
Third: Now i,m having one more problem:
this function *env = avs_create().
what kind of data is the result? Long? Integer? String? i guess is long for this:
Global avs_create_env.l (from the pure basic code)

Sorry for this stupid question ;-)

BTW: One friend of mine is C++ User.

So, if anybody can provide a C++ example, my friend can give me a "translation"

Sorry for bothering so much!!!!!

Thanks!!!!

Inc
14th June 2006, 17:23
As the avsRedirect.dll is a simple wrapper, you can easely use the source posted in the main thread as its C++ : http://forum.doom9.org/showthread.php?t=106125&highlight=avsredirect
This clearly shows how the approach is beeing done.

*env = avs_create().
what kind of data is the result?
A pointer to an IScriptenvironment, so by this its an adress stored in a pointervariable (at 32bit adress Systems its a 4byte long one)

In Purebasic:

"Variable.l" ... means a long one
"Variable.b" ... a byte one
"Variable.w" ... a word one
"Variable.s" ... a string
"*pointer" ... a pointer
"@Variable.l" ... a reference to a long Variable like in c++ "& hWindow"
"myBIH.BITMAPINFOHEADER" ... like in C++ "BITMAPINFOHEADER myBIH"
"myBIH\width" ... like in C++ "myBIH.width" or "myBIH->width"

winnydows
5th September 2006, 12:54
@OvejaNegra
How your problems ? I write in vb.net 2005 too. My program is XviD4PSP (http://forum.doom9.org/showthread.php?p=871651). And I`m not programmer too. Have you worked avsredirect sample solution for vb.net now ?