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.
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.