Getting AVI File Duration

I am using the VFW module from the JEDI shell in WinAPI.

The code I'm writing is designed to search for user drives and determine warez (note: deciding whether a file is legal or not is beyond the scope of this question). We do MP3, WMA and some image file search. Now we want to find illegal films. I want to open an AVI file, read some details 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, lLenMinutes is something equal to 98, while the film lasts about 121 minutes. This is a huge difference. What am I doing wrong? dwRate is 1 million and dwScale is 40k, so FPS is excellent 25. dwLength 147k MSDN says : "The units are determined by dwRate and dwScale."

Note: this is a continuation of this question , but since the crash problem was resolved, I closed another question and moved the improved content here.

0
source share
1 answer

MSDN says for dwScale AVIFILEINFO member:

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

Are you sure that the streams do not override the speed and scale specified in the AVIFILEINFO structure? The speed and scale for the stream are stored in the AVISTREAMINFO structure.

+2
source

Source: https://habr.com/ru/post/1393921/


All Articles