获取AVI文件持续时间 [英] Getting AVI file duration

查看:173
本文介绍了获取AVI文件持续时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在写的代码是用于搜索用户驱动器和检测warez(注意:决定是否有一些文件是否合法是超出了这个问题的范围)。我们做MP3,WMA和一些图形文件搜索。现在我们想检测非法电影。我想打开AVI文件,从中读取一些细节并关闭它。我有以下代码:

 使用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;
尝试
{打开文件 - 注意:因为我们搜索warez这是完美的warezy文件}
AVIFileOpen(lFile,'e:\Sideways KLAXXON\Sideways KLAXXON.avi' ,OF_READ,nil);
尝试
{获取文件信息}
AVIFileInfoW(lFile,lInfo,sizeof(lInfo));
lFPS:= Round(lInfo.dwRate /lInfo.dwScale);
lLenMinutes:= Round(lInfo.dwLength / lFPS / 60);
lFileType:= lInfo.szFileType;
{只是为了展示:准备一些备忘录,看看我们得到什么}
memo1.Lines.Clear;
memo1.Lines.Add('文件长度[min]:'+ IntToStr(lLenMinutes));
memo1.Lines.Add('Width:'+ IntToStr(lInfo.dwWidth));
memo1.Lines.Add('Height:'+ IntToStr(lInfo.dwHeight));
memo1.Lines.Add('文件类型:'+ lFileType);
finally
{关闭文件}
AVIFileRelease(lFile);
指针(lFile):= nil;
结束
终于
{发布库}
AVIFileExit;
结束
结束

所以lLenMinutes是等于98,而电影大约121分钟。这是一个巨大的区别。我究竟做错了什么? dwRate是100万,dwScale是40k,所以FPS是完美的25.dwLength是147k MSDN说:单位由dwRate和dwScale定义。



注意:这是一个从这个问题的跟进,但是由于崩溃的问题已经解决了,我关闭了另一个问题,并在这里提出了改进的内容。

解决方案

MSDN表示 dwScale 成员 AVIFILEINFO


任何流都可以定义自己的时间标度来取代文件的时间尺度。


您确定流不会覆盖 AVIFILEINFO 结构中给出的速率和比例吗?流的速率和比例存储在 AVISTREAMINFO 结构。


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.

解决方案

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.

这篇关于获取AVI文件持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆