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 > Programming and Hacking > Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 21st January 2006, 19:05   #1  |  Link
Inc
Squeeze it!
 
Inc's Avatar
 
Join Date: Oct 2003
Location: Germany
Posts: 472
A new version of AVSredirect.dll

Hi,

I went into the code of AVSredirect and modified it a bit so it could be more handy to appl. developers.

It will be accessed via stdcall and got some addons.

Avs Scripts now can be easely handled in VB, Delphi, Purebasic etc. without the common VFW workouts.
Scripts at given string pointers also can be handled.

Code:
*env = avs_create()

Creates a Scripenvironment for later use



ErrorLength = avs_getlasterror(char *str, int len))

Returns the length of the Errorstring which will be stored at the *str stringpointer



*char = avs_getlasterrorb()

Returns a string pointer where the last Error is stored.
The linebreaks of the string do come as chr(10)+chr(13) istead of a single chr(10)



clip = avs_open(*env, char *fname, AVSDLLVideoInfo *vi)

Opens an avs file, passes the VideoInfo to *vi and returns the clipnumber



clip = avs_script(*env, char *script, AVSDLLVideoInfo *vi, "RGB24")

Takes a string  (an avs script) strored at *script, passes the VideoInfo to *vi and returns the clipnumber.
Note, you can force the output to a given Colorpace. Options are "RGB24", "RGB32", "YV12" and "YVY2"



*p = avs_getvframe(*env, clip, frame )

Returns the adress where the Bitmap is stored.



avs_getaframe(*env, clip, *buffer, __int64 start, __int64 count)

Reads the audiodata from the sample start to the sample end and stores it at the given *buffer adress



avs_close(*env, clip)

Releases the clip and the scriptenvironment





The AVSdllVideoInfo Structure:

typedef struct AVSDLLVideoInfo {
	// Video
 	int width;
	int height;
	int raten;
	int rated;
	int aspectn;  // ?
	int aspectd;  // ?
	int interlaced_frame;
	int top_field_first;
	int num_frames;
	int pixel_type;

	// Audio
	int audio_samples_per_second;
	int sample_type;
	int nchannels;
	int num_audio_frames;
	int64_t num_audio_samples;
} AVSDLLVideoInfo;
Sources are included.

Inc.
Attached Files
File Type: zip New AVS Redirect.zip (58.0 KB, 535 views)

Last edited by Inc; 21st January 2006 at 19:11.
Inc is offline   Reply With Quote
Old 21st January 2006, 19:09   #2  |  Link
dimzon
BeHappy/MeGUI developer
 
dimzon's Avatar
 
Join Date: Oct 2003
Location: Moscow, Russia
Posts: 1,727
please, upload it @ mytemdir.com

PS. I just finished my own avsredirect modification
dimzon is offline   Reply With Quote
Old 21st January 2006, 19:13   #3  |  Link
Inc
Squeeze it!
 
Inc's Avatar
 
Join Date: Oct 2003
Location: Germany
Posts: 472
http://www.mytempdir.com/399643
Inc is offline   Reply With Quote
Old 22nd January 2006, 20:08   #4  |  Link
Amnon82
Paldo-GNU/LinuxMaintainer
 
Amnon82's Avatar
 
Join Date: Oct 2003
Location: Germany
Posts: 1,580
Can you post a short example how to use it in delphi?
Amnon82 is offline   Reply With Quote
Old 23rd January 2006, 09:48   #5  |  Link
Inc
Squeeze it!
 
Inc's Avatar
 
Join Date: Oct 2003
Location: Germany
Posts: 472
Create a scriptenvironment, open the avs-file or the avs-script-string, get the wanted videoframe, get the wanted audiodata, get the errors if the calls before did return an error value, if not --> .... play it.
Close the avs if you want to release the script.

Look into the sources - they are included as its GPL licensed - the sources speak for themself.
Inc is offline   Reply With Quote
Old 23rd January 2006, 18:37   #6  |  Link
dimzon
BeHappy/MeGUI developer
 
dimzon's Avatar
 
Join Date: Oct 2003
Location: Moscow, Russia
Posts: 1,727
@incredible
http://forum.doom9.org/showthread.ph...705#post773705
dimzon is offline   Reply With Quote
Old 23rd January 2006, 21:20   #7  |  Link
Inc
Squeeze it!
 
Inc's Avatar
 
Join Date: Oct 2003
Location: Germany
Posts: 472
Yupp, how about adding ...
Code:
env->BitBlt(bufferVidOut, outPitch, f->GetReadPtr(), f->GetPitch(), 
    f->GetRowSize(), f->GetHeight());
.. at the end of the avs_getvframe() routine?

But how obtaining the right value for the 'outPitch' depending on the Outputcolorspace (RGB24/32,YV12,YUY2) ?

Last edited by Inc; 23rd January 2006 at 21:22.
Inc is offline   Reply With Quote
Old 24th January 2006, 00:34   #8  |  Link
Inc
Squeeze it!
 
Inc's Avatar
 
Join Date: Oct 2003
Location: Germany
Posts: 472
I added to the the avs_getvframe() function the BitBlt() so the problem about the smartpointer issue should be solved:

Code:
int __stdcall avs_getvframe(IScriptEnvironment* env, int clip_num, BYTE *buf, int frm )
{
    try {
        PVideoFrame f = clip[clip_num]->GetFrame(frm, env);
		env->BitBlt(buf,f->GetPitch(), f->GetReadPtr(), f->GetPitch(),
			f->GetRowSize(), f->GetHeight());
		g_lasterr[0] = 0;
		return 0;
    } 
        
    catch(AvisynthError err) {
		strncpy(g_lasterr,err.msg,ERRMSG_LEN-1);	
		return -1;
	}

}
I used as destPitch in the BitBlt the sourcePitch as I do "assume" that it should be the same!?

I tested the playback and it works fine on a RGB24 previewing output.

Dimzon, I had a closer look at the mod's you did on AVSRedirect.
You did made a separate __patchScript() function, which makes sense, but in case of avs_open() you do force an YV12 output!
I have been even thinking about getting rid of the YV12 and YUY2 output option as it makes imho no sense in case of a wrapper which gots its purpose to provide Videoframes mainly for later displaying in previewing apps.
Inc is offline   Reply With Quote
Old 24th January 2006, 02:09   #9  |  Link
Sirber
retired developer
 
Sirber's Avatar
 
Join Date: Oct 2002
Location: Canada
Posts: 8,978
Permission to add to RealAnime
__________________
Detritus Software
Sirber is offline   Reply With Quote
Old 24th January 2006, 09:40   #10  |  Link
Inc
Squeeze it!
 
Inc's Avatar
 
Join Date: Oct 2003
Location: Germany
Posts: 472
Of course

But as you see its not really ready yet. Lets wait if the BitBlt approach above is correct done.
I want to implement a cropping/resizing function and some more addons.

Last edited by Inc; 24th January 2006 at 09:43.
Inc is offline   Reply With Quote
Old 24th January 2006, 11:37   #11  |  Link
dimzon
BeHappy/MeGUI developer
 
dimzon's Avatar
 
Join Date: Oct 2003
Location: Moscow, Russia
Posts: 1,727
Quote:
Originally Posted by incredible
I added to the the avs_getvframe() function the BitBlt() so the problem about the smartpointer issue should be solved
So You choose 1-st variant (CPU && Memory consuming)
dimzon is offline   Reply With Quote
Old 24th January 2006, 12:48   #12  |  Link
dimzon
BeHappy/MeGUI developer
 
dimzon's Avatar
 
Join Date: Oct 2003
Location: Moscow, Russia
Posts: 1,727
Quote:
Originally Posted by incredible
I added to the the avs_getvframe() function the BitBlt() so the problem about the smartpointer issue should be solved
Unfortunally my knoledge about AviSynth internals are poor.
Waht does I obtain @ the output, how I must threat this values, which buffer size i must provide to to this function?
dimzon is offline   Reply With Quote
Old 24th January 2006, 13:31   #13  |  Link
Sirber
retired developer
 
Sirber's Avatar
 
Join Date: Oct 2002
Location: Canada
Posts: 8,978
@incredible

Is it ready for at least getting the audio and video informations?
__________________
Detritus Software
Sirber is offline   Reply With Quote
Old 24th January 2006, 13:32   #14  |  Link
dimzon
BeHappy/MeGUI developer
 
dimzon's Avatar
 
Join Date: Oct 2003
Location: Moscow, Russia
Posts: 1,727
Quote:
Originally Posted by Sirber
@incredible

Is it ready for at least getting the audio and video informations?
Yes! It's even working for getting raw audio data from it (MeGIU use it to encode audio)
dimzon is offline   Reply With Quote
Old 24th January 2006, 13:42   #15  |  Link
Sirber
retired developer
 
Sirber's Avatar
 
Join Date: Oct 2002
Location: Canada
Posts: 8,978
Cool! I will try it this weekend! Thanks!
__________________
Detritus Software
Sirber is offline   Reply With Quote
Old 24th January 2006, 13:51   #16  |  Link
Inc
Squeeze it!
 
Inc's Avatar
 
Join Date: Oct 2003
Location: Germany
Posts: 472
@ Dimzon

In PureBasic Syntax

*buf = AllocateMemory( vi.width * vi.height * 3 ) ;// an RGB 24 buffer
avs_getvframe(*env, clip_num, *buf, frm )

thats like if you do avs_getaframe().

By doing this you get a 'naked' raw RGB24 Bitmap at *buf.
The result value out of the call itself is just a bool like in the other function calls incl. providig the error string to the getlasterror() function if a -1 returns.
Then use a predifined BITMAPINFOHEADER Structure where you do set the obligatory values for width, height, planes, bitcount etc.
Pass these values to the APIs SetDIBits() command and you will have a standard RGB24 Bitmap for displaying in an imageframe.

I do assume as MeGUI also obtaines raw RGB24 Bitmaps out of the DgDecode access, so do look how in MeGUI those raw Bitmaps will be treaten to be displayed in a picture frame.

Last edited by Inc; 24th January 2006 at 14:44.
Inc is offline   Reply With Quote
Old 24th January 2006, 13:54   #17  |  Link
Inc
Squeeze it!
 
Inc's Avatar
 
Join Date: Oct 2003
Location: Germany
Posts: 472
Quote:
Originally Posted by Sirber
@incredible

Is it ready for at least getting the audio and video informations?
These also can be simply obtained via the Windows AviFil32 API (Avistreaminfo/AvifileInfo/BitmapInfoheader etc.) and The VFW API's ICOpen Routines (decompressor query for instance etc), which are included in your system32 as dlls.
So you dont have to provide another dll like the one provided in here with your applikation
Inc is offline   Reply With Quote
Old 24th January 2006, 14:13   #18  |  Link
Sirber
retired developer
 
Sirber's Avatar
 
Join Date: Oct 2002
Location: Canada
Posts: 8,978
Quote:
Originally Posted by incredible
These also can be simply obtained via the Windows AviFil32 API (Avistreaminfo/AvifileInfo/BitmapInfoheader etc.) and The VFW API's ICOpen Routines (decompressor query for instance etc), which are included in your system32 as dlls.
So you dont have to provide another dll like the one provided in here with your applikation
My application already come with lots of DLLs and EXEs. Also, I specificly need AVS informations, for AVI & etc I already manage that. I just need to know if the AVS contain video and/or audio, so I can manage the encoding process.
__________________
Detritus Software
Sirber is offline   Reply With Quote
Old 24th January 2006, 14:31   #19  |  Link
Inc
Squeeze it!
 
Inc's Avatar
 
Join Date: Oct 2003
Location: Germany
Posts: 472
Code:
struct AVSDLLVideoInfo {
	// Video
 	int width;   // From AvifileInfo
	int height;  // From AvifileInfo
	int raten;   // From AviStreamInfo
	int rated;   // From AviStreamInfo
	int aspectn;  // -->Not provided viy Avisynth
	int aspectd;  // -->Not provided viy Avisynth
	int interlaced_frame; // really needed?
	int top_field_first; // really needed? and if ... is this result proof?
	int num_frames; // From AviStreamInfo
	int pixel_type; From the BitmapInfoHeader

	// Audio
	int audio_samples_per_second; // From AviStreamInfo/StreamTypeAudio-->WaveFormatEx
	int sample_type; // From AviStreamInfo/StreamTypeAudio-->WaveFormatEx
	int nchannels; // From AviStreamInfo/StreamTypeAudio-->WaveFormatEx
	int num_audio_frames; // From AviStreamInfo/StreamTypeAudio
	int64_t num_audio_samples; // Calculate from above
}
So all you need you can get from the AviFil32 API (this is just BTW)
If you need some Infos *ring the bell*

Quote:
Originally Posted by Dimzon
So You choose 1-st variant (CPU && Memory consuming)
Memory consuming? The *buf adress is fixed (in Purebasic its generated by 'pointer = AllocateMemory(size)' )where all frames will be stored at that adress and it consumpts (width*height*3) bytes.
The *buf generation is done before the getting frames loop.
And the avs BitBlt function seems to be verrry fast related to dev reports in here.

Thats btw. the approch included in Triticals Brief explanation some threads below.

EDIT: Wait ....

Quote:
Originally Posted by Dimzon
(*frame)->GetReadPtr()
Means I just pass the adress to a pointer *frame ? Thats all?
I did understand that the framedata in the memory at the "smart pointer" could get lost? And not the Adress itself!?

Last edited by Inc; 24th January 2006 at 14:45.
Inc is offline   Reply With Quote
Old 24th January 2006, 15:42   #20  |  Link
Sirber
retired developer
 
Sirber's Avatar
 
Join Date: Oct 2002
Location: Canada
Posts: 8,978
"AviFil32 API" can open AVS?
__________________
Detritus Software
Sirber 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 21:09.


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