Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

AVI File Info

9 views
Skip to first unread message

Martin

unread,
Jun 11, 2004, 5:08:42 AM6/11/04
to
I'm a newbie teaching myself Delphi 7.

I'm looking for info - tutorials, guides etc - for how to get the properties
of a video file.
I want to select a video file (mainly AVI filetype) and ascertain it's:

Resolution.
Framerate.
Duration.
Audio/Video bitrates.

I've been going round in circles browsing the www getting nowhere.
I found www.progdigy.com and have downloaded the DSPack but find no
beginners documentation.
I've searched the DSPack forum but find only info that is too advanced for
me!

Can anyone point me in the right direction?
What's the bare minimum that i'll need to install - is the DirectX SDK
necessary?
Any very basic code example would be much appreciated - the properties i
listed above are really the only details that i need to extract from the
video files.

Thanks for anyone that takes the time to answer.

Martin.


Wayne Sherman

unread,
Jun 11, 2004, 12:43:09 PM6/11/04
to
> I'm looking for info - tutorials, guides etc - for how to
> get the properties of a video file

The GetMediaInfo code below shows how to get some of this information. It is
older code, so there might be standardized ways to get at this data in
DX9/DirectShow now. You need to install a DirectX and DirectShow SDK/header
conversion to use some of these interfaces.

type
TDSMediaInfo = record
SurfaceDesc: TDDSurfaceDesc;
Pitch: integer;
PixelFormat: TPixelFormat;
MediaLength: Int64;
AvgTimePerFrame: Int64;
FrameCount: integer;
Width: integer;
Height: integer;
FileSize: Int64;
end;

function GetHugeFileSize(const FileName: string): int64;
type
TFileSize = packed record
LowPart: DWORD;
HighPart: DWORD;
end;
var
FindData: TWIN32FindData;
SearchHandle: THandle;
begin
SearchHandle := FindFirstFile(PChar(FileName), FindData);
if SearchHandle = INVALID_HANDLE_VALUE then RaiseLastWin32Error;

TFileSize(Result).LowPart := FindData.nFileSizeLow;
TFileSize(Result).HighPart := FindData.nFileSizeHigh;

Windows.FindClose(SearchHandle);
end;


function GetMediaInfo(FileName: WideString): TDSMediaInfo;
var
DirectDraw: IDirectDraw;
AMStream: IAMMultiMediaStream;
MMStream: IMultiMediaStream;
PrimaryVidStream: IMediaStream;
DDStream: IDirectDrawMediaStream;
GraphBuilder: IGraphBuilder;
MediaSeeking: IMediaSeeking;
DesiredSurface: TDDSurfaceDesc;
DDSurface: IDirectDrawSurface;
begin
if FileName = '' then raise Exception.Create('No File Name Specified');

OleCheck(DirectDrawCreate(nil, DirectDraw, nil));
DirectDraw.SetCooperativeLevel(GetDesktopWindow(), DDSCL_NORMAL);

Result.FileSize := GetHugeFileSize(FileName);

AMStream := IAMMultiMediaStream(CreateComObject(CLSID_AMMultiMediaStream));
OleCheck(AMStream.Initialize(STREAMTYPE_READ, AMMSF_NOGRAPHTHREAD, nil));
OleCheck(AMStream.AddMediaStream(DirectDraw, MSPID_PrimaryVideo,
0, IMediaStream(nil^)));
OleCheck(AMStream.OpenFile(PWideChar(FileName), AMMSF_NOCLOCK));

AMStream.GetFilterGraph(GraphBuilder);
MediaSeeking := GraphBuilder as IMediaSeeking;

MediaSeeking.GetDuration(Result.MediaLength);

MMStream := AMStream as IMultiMediaStream;
OleCheck(MMStream.GetMediaStream(MSPID_PrimaryVideo, PrimaryVidStream));
DDStream := PrimaryVidStream as IDirectDrawMediaStream;

DDStream.GetTimePerFrame(Result.AvgTimePerFrame);

Result.FrameCount := Round(Result.MediaLength / Result.AvgTimePerFrame);
Result.MediaLength := Result.FrameCount * Result.AvgTimePerFrame;

ZeroMemory(@DesiredSurface, SizeOf(DesiredSurface));
DesiredSurface.dwSize := Sizeof(DesiredSurface);

OleCheck(DDStream.GetFormat(TDDSurfaceDesc(nil^),
IDirectDrawPalette(nil^), DesiredSurface, DWord(nil^)));

Result.SurfaceDesc := DesiredSurface;

DesiredSurface.ddsCaps.dwCaps := DesiredSurface.ddsCaps.dwCaps or
DDSCAPS_OFFSCREENPLAIN or DDSCAPS_SYSTEMMEMORY;

DesiredSurface.dwFlags := DesiredSurface.dwFlags or DDSD_CAPS
or DDSD_PIXELFORMAT;

//Create a surface here to get vital statistics
OleCheck(DirectDraw.CreateSurface(DesiredSurface, DDSurface, nil));
OleCheck(DDSurface.GetSurfaceDesc(DesiredSurface));
Result.Pitch := DesiredSurface.lPitch;
if DesiredSurface.ddpfPixelFormat.dwRGBBitCount = 24 then
Result.PixelFormat := pf24bit
else if DesiredSurface.ddpfPixelFormat.dwRGBBitCount = 32 then
Result.PixelFormat := pf32bit;
Result.Width := DesiredSurface.dwWidth;
Result.Height := DesiredSurface.dwHeight;
end;


Regards,

Wayne Sherman
Las Vegas


0 new messages