PDA

View Full Version : <Delphi> Get information of AVS using VFW or AVISYNTH_C-Port by Myrsloik


Amnon82
6th January 2005, 02:21
How do you get the informations out of an avs-file. The answer is vfw or avisynth_c.

In the first part of this post I show you the way how to get the informations using vfw. The second part shows you the way using avisynth_c.

VFW stands for VideoForWindows. VFW was ported to Delphi. Take a look on the code and the sources of mine.

Code how to use vfw in Delphi:


uses vfw

{The GetAVSFrames function will give You the Info about the AVS-File
(C) 2005-2006 by Amnon82}

function GETAVSFRAMES(avifn: string): Boolean;
var
Error: Integer;
pFile: PAVIFile;
AviInfo: TAVIFILEINFOW;
sError: string;
begin
Result := False;
// Initialize the AVIFile library.
AVIFileInit;

// The AVIFileOpen function opens an AVI file
Error := AVIFileOpen(pFile, PChar(avifn), 0, nil);
if Error <> 0 then
begin
AVIFileExit;
{case Error of
AVIERR_BADFORMAT: sError := 'The file couldn''t be read';
AVIERR_MEMORY: sError := 'The file could not be opened because of insufficient memory.';
AVIERR_FILEREAD: sError := 'A disk error occurred while reading the file.';
AVIERR_FILEOPEN: sError := 'A disk error occurred while opening the file.';
end; }
sError := 'The AVS-file could not be opened. Check it.';
Messagebox(Application.Handle, pchar(sError), pchar('Error'),
MB_ICONERROR);
Exit;
end;

// AVIFileInfo obtains information about an AVI file
if AVIFileInfo(pFile, @AVIINFO, SizeOf(AVIINFO)) <> AVIERR_OK then
begin
// Clean up and exit
AVIFileRelease(pFile);
AVIFileExit;
Exit;
end;

// Show some information about the AVI
// You can create some edits to write in the infos
Form1.avsframes.text:=IntToStr(AVIINFO.dwLength);
Form1.avsheight.text:=IntToStr(AVIINFO.dwheight);
Form1.avswidth.text:=IntToStr(AVIINFO.dwWidth);
Form1.rate.text:=formatfloat('0.000',AVIINFO.dwRate/AVIINFO.dwScale);
end;

// Usage:
GETAVSFRAMES(AVSFILENAMESTRING);



You can download the Sources by Amnon82 (http://home.arcor.de/autoq2_amsoft/files/delphi/source/GETAVSINFOS_SOURCE.zip) to get the feeling how to use vfw in Delphi.

==============================================================================

http://img463.imageshack.us/img463/9858/avisynthc3zf.png

Myrsloik did a avisynth_c-port (http://home.arcor.de/autoq2_amsoft/files/delphi/source/avisynth_pascal_v3.7z). Now you can use avisynth_c without the need of vfw. Your programs running faster and more stable.

Myrsloik created some samples how to use the avisnyth_c-port in Delphi. It shows you the framecount, resolution and field order (TFF).

Code how to use avisynth_c in Delphi:
uses avisynth_c

var avsval:AVS_Value;
begin
if OpenDialog1.Execute then
begin
//call avisouce with the selected filename
avsval:=avs_invoke(env,'AVISource',avs_new_value_string(PChar(OpenDialog1.FileName)));

//check for errors, only AVS_Values containing clips need to be freed
//which it won't here if it's an error
if avs_is_error(avsval) then
raise EAviSynthCException.Create(avs_as_error(avsval));

//get a clip from the AVS_Value
clip:=avs_take_clip(avsval,env);

//release the AVS_Value since it contained a clip, releasing an AVS_Value
//without a clip does nothing
avs_release_value(avsval);

//get video information and adjust window
vi:=avs_get_video_info(clip);

TrackBar1.Max:=vi.num_frames-1;
ClientWidth:=vi.width;
ClientHeight:=vi.height+TrackBar1.Height;

with Image1.Picture.Bitmap do
begin
Width:=vi.width;
Height:=vi.height;

if avs_is_rgb32(vi) then
PixelFormat:=pf32bit
else if avs_is_rgb24(vi) then
PixelFormat:=pf24bit
end;

TrackBar1Change(nil);
end;
end;

You can download the Sources by Myrsloik (http://home.arcor.de/autoq2_amsoft/files/delphi/source/avisynth_c_sample.7z) to get the feeling how to use avisynth_c in Delphi. Thx goes again to Myrsloik.

Moitah
6th January 2005, 02:36
I don't know any Delphi, but you would do it the same way as you would with any AVI (AVIFileInit, AVIFileOpen, AVIFileGetStream, AVIStreamInfo, AVIStreamRelease, AVIFileClose, AVIFileExit). Here's how it's done in C++, let me know if you have any questions:
#include <iostream>
#include <windows.h>
#include <vfw.h>

using namespace std;

int main(int argc, char* argv[]) {
char *pathSrc;
PAVIFILE pAviFile;
PAVISTREAM pVideoStream;
AVISTREAMINFO videoStreamInfo;
bool finished;

if (argc < 2) {
return 0;
}

finished = false;
pathSrc = argv[1];

AVIFileInit();

if (AVIFileOpen(&pAviFile, pathSrc, OF_SHARE_DENY_WRITE, 0) == AVIERR_OK) {
if (AVIFileGetStream(pAviFile, &pVideoStream, streamtypeVIDEO, 0) == AVIERR_OK) {
ZeroMemory(&videoStreamInfo, sizeof(AVISTREAMINFO));
if (AVIStreamInfo(pVideoStream, &videoStreamInfo, sizeof(AVISTREAMINFO)) == AVIERR_OK) {
finished = true;
}
AVIStreamRelease(pVideoStream);
}
AVIFileClose(pAviFile);
}

AVIFileExit();

if (finished) {
cout << "Length: " << videoStreamInfo.dwLength << "\n";
}
else {
cout << "An error occurred.\n";
}

return 0;
}

Amnon82
6th January 2005, 11:38
I got it!

http://www.brckomania.net/AUTOQ/OpenSource/GetAVIS.png

It tooks 2h to get this code.
Now You can get the Infos of Your
AVS also in Delphi

THX goes to Moitah from the doom9.org forum
for pointing me to vfw. THX again dude!

You can use this code for all your projects.
I hope it can help You out.

Best regards

Amnon82

esby
7th January 2005, 13:43
you could also grab lbkiller sources and look on the (*)vfw libraries.
(follow the link after my sign)

esby

Amnon82
20th January 2005, 19:05
THX esby, I'll give it a try.

SLYP
28th January 2005, 22:40
Hi

I am also writing an application in C++, that reads in avs scripts and modifies info in ecl file for CCE or tpr file for tmpg.

At the moment I have done a work around to get the height, width etc by automatically adding a line to the avs script which writes the values to a txt file and then i read them in from there as variables. I was just thinking of changing this as I dont see it as the most efficient way of doing thing.

I was looking into as to wether its possible to link to the avisynth dll and get the details from there. But having not done too much with dlls before i dont know where to start. I've had a look at the dll file via dependency walker and see the function avs_get_video_info. Can anyone shed light as to how i would get the information from a script i loaded into my program via this method?

On the other hand perhaps the best way would be to use the helpful code Moitah has provided to do the job.

Sirber
26th January 2006, 01:55
http://www.brckomania.net/AUTOQ/OpenSource/GETAVSINFOS_SOURCE.rar

Firefox can't establish a connection to the server at www.sedoparking.com.

I'd like to have a look :(

alfixdvd
26th January 2006, 16:03
Impossible to get file at url http://www.brckomania.net/AUTOQ/OpenSource/GETAVSINFOS_SOURCE.rar

I get HTTP/1.1 404 Not Found

What's wrong?

Moitah
26th January 2006, 19:33
I had it laying on my hard drive: GETAVSINFOS_SOURCE.rar (http://www.moitah.net/misc/GETAVSINFOS_SOURCE.rar)

alfixdvd
26th January 2006, 20:04
Thanks Moitah.

Best regards.

ADLANCAS
27th January 2006, 23:29
Hi,
You could get frames from a "primitive" text file created by avs2avi.
Put in a bat file:
"C:\Program Files\Avsvs2avi\avs2avi.exe" "D:\name.avs" -e -c null | find "Frames" > "D:\frames.txt"

Maybe someone (like me) thinks that is useful.

Alexandre

pest
1st February 2006, 17:58
does someone know how much speed you'll loose when using avisynth
through vfw?

Ebobtron
1st February 2006, 18:59
does someone know how much speed you'll loose when using avisynth
through vfw?The application avsFilmCutter (http://forum.doom9.org/showthread.php?t=97438) I am working on currently uses both a direct interface and a VFW interface to gather info about an AviSynth script. I don't see a significant difference in access speed. It kind of depends on your code. A great example of how to slow a multi-gig system is the way FilmCutter displays a list of internal and plugin functions in the script editor window (from FilmCutter' script editor menu select AviSynth options -> Display filter list). If you fetch things one at a time, as the above described function does, then you can slow anything down. The VFW library of functions are used by VirtualDub, QuEnc, AviSynth and many more, don't seem to slow them down.

Amnon82
5th February 2006, 14:37
Since the PC only displays RGB and the first sample couldn't display YUV2 and YV12, I found a way to do it.
Take a look on the new source (home.arcor.de/autoq2_amsoft/files/delphi/source/avisynth_c_sample_v3.zip).

http://img145.imageshack.us/img145/4881/untitled21ov.th.png (http://img145.imageshack.us/my.php?image=untitled21ov.png)

Stander
21st April 2008, 08:25
Hi!

As I can see this can be a great base for building AviSynth scripts player.
Is it possible to capture and play also an audio stream?

Regards,
Stander