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
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 6th January 2005, 02:21   #1  |  Link
Amnon82
Paldo-GNU/LinuxMaintainer
 
Amnon82's Avatar
 
Join Date: Oct 2003
Location: Germany
Posts: 1,580
<Delphi> Get information of AVS using VFW or AVISYNTH_C-Port by Myrsloik

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:
Code:
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 to get the feeling how to use vfw in Delphi.

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



Myrsloik did a avisynth_c-port. 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:
Code:
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 to get the feeling how to use avisynth_c in Delphi. Thx goes again to Myrsloik.

Last edited by Amnon82; 22nd June 2006 at 14:29.
Amnon82 is offline   Reply With Quote
Old 6th January 2005, 02:36   #2  |  Link
Moitah
Registered User
 
Join Date: Feb 2004
Location: Virginia, USA
Posts: 334
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:
Code:
#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;
}
__________________
moitah.net
Moitah is offline   Reply With Quote
Old 6th January 2005, 11:38   #3  |  Link
Amnon82
Paldo-GNU/LinuxMaintainer
 
Amnon82's Avatar
 
Join Date: Oct 2003
Location: Germany
Posts: 1,580
I got it!



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

Last edited by Amnon82; 22nd June 2006 at 14:30.
Amnon82 is offline   Reply With Quote
Old 7th January 2005, 13:43   #4  |  Link
esby
Registered User
 
esby's Avatar
 
Join Date: Oct 2001
Location: france
Posts: 521
you could also grab lbkiller sources and look on the (*)vfw libraries.
(follow the link after my sign)

esby
__________________
http://esby.free.fr/
esby is offline   Reply With Quote
Old 20th January 2005, 19:05   #5  |  Link
Amnon82
Paldo-GNU/LinuxMaintainer
 
Amnon82's Avatar
 
Join Date: Oct 2003
Location: Germany
Posts: 1,580
THX esby, I'll give it a try.
Amnon82 is offline   Reply With Quote
Old 28th January 2005, 22:40   #6  |  Link
SLYP
Registered User
 
Join Date: Feb 2003
Posts: 4
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.
SLYP is offline   Reply With Quote
Old 26th January 2006, 01:55   #7  |  Link
Sirber
retired developer
 
Sirber's Avatar
 
Join Date: Oct 2002
Location: Canada
Posts: 8,978
http://www.brckomania.net/AUTOQ/Open...FOS_SOURCE.rar

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

I'd like to have a look
__________________
Detritus Software
Sirber is offline   Reply With Quote
Old 26th January 2006, 16:03   #8  |  Link
alfixdvd
Registered User
 
Join Date: Mar 2004
Posts: 243
Impossible to get file at url http://www.brckomania.net/AUTOQ/Open...FOS_SOURCE.rar

I get HTTP/1.1 404 Not Found

What's wrong?

Last edited by alfixdvd; 26th January 2006 at 16:06.
alfixdvd is offline   Reply With Quote
Old 26th January 2006, 19:33   #9  |  Link
Moitah
Registered User
 
Join Date: Feb 2004
Location: Virginia, USA
Posts: 334
I had it laying on my hard drive: GETAVSINFOS_SOURCE.rar
__________________
moitah.net
Moitah is offline   Reply With Quote
Old 26th January 2006, 20:04   #10  |  Link
alfixdvd
Registered User
 
Join Date: Mar 2004
Posts: 243
Thanks Moitah.

Best regards.
alfixdvd is offline   Reply With Quote
Old 27th January 2006, 23:29   #11  |  Link
ADLANCAS
Registered User
 
ADLANCAS's Avatar
 
Join Date: Apr 2003
Location: Brazil
Posts: 247
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
ADLANCAS is offline   Reply With Quote
Old 1st February 2006, 17:58   #12  |  Link
pest
Registered User
 
Join Date: Feb 2005
Posts: 39
does someone know how much speed you'll loose when using avisynth
through vfw?
pest is offline   Reply With Quote
Old 1st February 2006, 18:59   #13  |  Link
Ebobtron
Errant Knight
 
Ebobtron's Avatar
 
Join Date: Oct 2004
Location: St Louis, M0 US
Posts: 364
Quote:
Originally Posted by pest
does someone know how much speed you'll loose when using avisynth
through vfw?
The application avsFilmCutter 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.

Last edited by Ebobtron; 1st February 2006 at 19:01.
Ebobtron is offline   Reply With Quote
Old 5th February 2006, 14:37   #14  |  Link
Amnon82
Paldo-GNU/LinuxMaintainer
 
Amnon82's Avatar
 
Join Date: Oct 2003
Location: Germany
Posts: 1,580
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.


Last edited by Amnon82; 22nd June 2006 at 14:31.
Amnon82 is offline   Reply With Quote
Old 21st April 2008, 07:25   #15  |  Link
Stander
Registered User
 
Join Date: Mar 2008
Posts: 1
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
Stander is offline   Reply With Quote
Reply


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 09:56.


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