English 中文(简体)
Getting AVI file duration
原标题:

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

最佳回答

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.

问题回答

暂无回答




相关问题
determining the character set to use

my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...

Help with strange Delphi 5 IDE problems

Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How convert string to integer in Oxygene

In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签