views:

252

answers:

1

I am using VFW unit from JEDI wrapper on WinAPI.

The code I am writing is intended to search user drives and detect warez (note: deciding if some file is legal or not is beyond scope of this question). We do MP3, WMA and some graphic file search. Now we want to detect illegal movies. I want to open AVI file, read some details from it and close it. I have the following code:

uses WFV; //from JEDI api wrappers

procedure TForm1.Button1Click(Sender: TObject);
var
  lInfo : TAVIFILEINFOW;
  lFile : IAVIFILE;
  lFileType : string;
  lLenMinutes : integer;
  lFPS : integer;
begin
  {init file}
  AVIFileInit;
  try
    {Open file - note: since we search for warez this is perfely "warezy" file}
    AVIFileOpen(lFile, 'e:\Sideways KLAXXON\Sideways KLAXXON.avi', OF_READ, nil);
    try
      {Get file info} 
      AVIFileInfoW(lFile, lInfo, sizeof(lInfo));
      lFPS:=Round(lInfo.dwRate /lInfo.dwScale);
      lLenMinutes := Round(lInfo.dwLength  / lFPS / 60);
      lFileType := lInfo.szFileType;
      {just for show: prepare some memo to see what we get}
      memo1.Lines.Clear;
      memo1.Lines.Add('File lenght [min]: ' + IntToStr(lLenMinutes));
      memo1.Lines.Add('Width: ' + IntToStr(lInfo.dwWidth));
      memo1.Lines.Add('Height: ' + IntToStr(lInfo.dwHeight));
      memo1.Lines.Add('File type: ' + lFileType);
    finally
      {Closing the file}
      AVIFileRelease (lFile);
      Pointer(lFile) := nil;
    end;
  finally
    {Releasing library}
    AVIFileExit;
  end;
end;

So the lLenMinutes is something equal to 98 while the movie is about 121 minutes long. This is a huge difference. What am I doing wrong? dwRate is 1 million and dwScale is 40k, so the FPS is perfectly 25. dwLength is 147k MSDN says: “The units are defined by dwRate and dwScale”.

Note: this is a follow-up from this question, but since the crashing problem has been solved, I closed the other question and moved improved content here.

+2  A: 

MSDN says for the dwScale member of AVIFILEINFO:

Any stream can define its own time scale to supersede the file time scale.

are you sure the streams does not override the rate and scale given in the AVIFILEINFOstructure ? the rate and scale for a stream is stored in an AVISTREAMINFO structure.

Adrien Plisson