Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Frame rate of a video

Posted on 2003-10-21
4
Medium Priority
?
232 Views
Last Modified: 2010-04-03
How can you get the frame rate of an AVI file?
0
Comment
Question by:jpedwards
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 9

Expert Comment

by:ginsonic
ID: 9596220
{File: AVIObjects.pas
Author: Liran Shahar
Purpose: AVI file objects routines to open,read and retrive poster frames (first frame in AVI file)
Copyright(C) 2001, Com-N-Sense Ltd, all rights reserved

Note: this unit is released as freeware. In other words, you are free  to use this unit in your own
applications, however I retain all copyright to the code. LS}


unit AVIObjects;

interface

uses
  Windows, Graphics, Sysutils, Classes, VFW, Ole2;

type
  TAviFileStream = class(TPersistent)
  private
    aviFile: IAviFile;
    aviStream: IAviStream;
    aviFrame: IGetFrame;
    aviInfo: TAviStreamInfo;
  protected
    function GetFrameCount: cardinal; virtual;
    function GetDuration: double; virtual;
    function GetWidth: integer; virtual;
    function GetHeight: integer; virtual;
    function GetWantedBitmapFormat: PBitmapInfoHeader; virtual;
  public
    constructor Create; virtual;
    destructor Destroy; override;
    function Active: boolean; virtual;
    procedure Open(const Filename: AnsiString); virtual;
    procedure Close; virtual;
    procedure GetFrame(FrameNumber: cardinal; var DIB: PBitmapInfoHeader); virtual;
    property FrameCount: cardinal read GetFrameCount;
    property Duration: double read GetDuration;
    property ImageWidth: integer read GetWidth;
    property ImageHeight: integer read GetHeight;
  end;

implementation


constructor TAviFileStream.Create;
begin
  inherited Create;
  aviFile := nil;
  aviStream := nil;
  aviFrame := nil;
end;


destructor TAviFileStream.Destroy;
begin
  Close;
  inherited Destroy;
end;


function TAviFileStream.Active: boolean;
begin
  Result := (aviStream <> nil) and (aviFrame <> nil);
end;


function TAviFileStream.GetFrameCount: cardinal;
begin
  Result := aviInfo.dwLength;
end;


function TAviFileStream.GetDuration: double;
begin
  if (aviInfo.dwRate <> 0) and (aviInfo.dwScale <> 0) then
    Result := aviInfo.dwLength / (aviInfo.dwRate / aviInfo.dwScale)
  else
    Result := 0.0;
end;


function TAviFileStream.GetWidth: integer;
begin
  Result := aviInfo.rcFrame.Right - aviInfo.rcFrame.Left;
end;


function TAviFileStream.GetHeight: integer;
begin
  Result := aviInfo.rcFrame.Bottom - aviInfo.rcFrame.Top;
end;


function TAviFileStream.GetWantedBitmapFormat: PBitmapInfoHeader;
begin
  Result := nil;
end;


procedure TAviFileStream.Open(const Filename: AnsiString);
var
  iResult: integer;
  BmpInfoHeader: PBitmapInfoHeader;
begin
  Close;
  fillchar(aviInfo,sizeof(aviInfo),0);
  iResult := AviFileOpen(aviFile, pchar(FileName), OF_READ + OF_SHARE_DENY_WRITE, nil);
  if iResult <> AVIERR_OK then
    raise Exception.Create('Cannot open AVI file ' + Filename);
  iResult := AVIFileGetStream(aviFile, aviStream, streamTypeVideo, 0);
  if iResult <> AVIERR_OK then
    raise Exception.Create('Cannot open stream for that file');
  iResult := AVIStreamInfo(aviStream, aviInfo, sizeof(aviInfo));
  if iResult <> AVIERR_OK then
    raise Exception.Create('Cannot read stream info');
  BmpInfoHeader := GetWantedBitmapFormat;
  aviFrame := AVIStreamGetFrameOpen(aviStream, BmpInfoHeader);
  if not assigned(aviFrame) then
    raise Exception.Create('Cannot find suitable decompressor');
  if assigned(BmpInfoHeader) then
    dispose(BmpInfoHeader);
end;


procedure TAviFileStream.Close;
var
  iResult: integer;
begin
  aviFrame := nil;
  aviStream := nil;
  aviFile := nil;
end;


procedure TAviFileStream.GetFrame(FrameNumber: cardinal; var DIB: PBitmapInfoHeader);
begin
  DIB := aviStreamGetFrame(aviFrame, FrameNumber)
end;


initialization
  CoInitialize(nil);
  AVIFileInit;


finalization
  AVIFileExit;
  CoUninitialize;

end.
0
 

Author Comment

by:jpedwards
ID: 9596461
Thanks for the response.

I pasted in your code and could not find file "VFW.dcu".
0
 
LVL 9

Accepted Solution

by:
ginsonic earned 2000 total points
ID: 9604350
This can be find on net. Just use Delphi+vfw.pas on Google.
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 9604361
As another option to solve your problem is to use DSPack library. Is freeware with source codes and sample projects and work for a lots of video format, including divX.

http://sourceforge.net/projects/dspack

8<---
DSPack is a set of Components and class to write Multimedia Applications using MS Direct Show and DirectX technologies. DSPack 2.3 is designed to work with DirectX 9 on Win9X, ME, 2000, and Windows XP operating systems using Delphi 5,6,7 and BCB6.
--->8

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question