NiTroGen
23rd March 2003, 02:46
I've tried to use Aquaplaning's vidframe.dll with Visual Basic 6, but I couldn't do it. Vidframe.dll (which can be found here (http://aquaplaning.20m.com)) is a dll created for Delphi to view, resize and crop frames from any direct show source. Here is the Delphi unit which uses the dll to access video frames:
unit vidframe;
interface
uses SysUtils, Graphics;
type
float = Double;
TMyColor = record
case Integer of
0: (c: TColor);
1: (r, g, b, x: byte);
2: (l: LongInt);
end;
TVideoInfo = record
width, height, // width=0 means no video
fps_numerator, fps_denominator, num_frames: integer;
pixel_type: word; // UNKNOWN=0, YUY2=2, BGR24=3 }
audio_samples_per_second, // 0 means no audio
num_audio_samples: integer;
stereo, sixteen_bit, field_based: boolean;
end;
PVideoInfo = ^TVideoInfo;
var videoInfo: PVideoInfo;
frameBM: TBitMap;
isVideoOpen: boolean;
// capsulated functions for delphi, recommended for use
procedure openDirectShow(name: String);
procedure openAVI(name: String);
procedure closeVideo;
procedure getFrame(frame: integer);
function getWidth: integer;
function getHeight: integer;
function getFrameCount: integer;
function getFPS: float;
// direct access to DLL function's
function openDirectShowDll(name: PChar): PVideoInfo; cdecl;
function openAVIDll(name: PChar): PVideoInfo; cdecl;
procedure closeVideoDll; cdecl;
function getFrameDll(frame: integer): PByteArray; cdecl;
function getWidthDLL: integer; cdecl;
function getHeightDLL: integer; cdecl;
function getFramecountDLL: integer; cdecl;
implementation
function openDirectShowDll(name: PChar): PVideoInfo; cdecl; external 'vidframe.dll' name '?openDirectShow@@YAPAUVideoInfo@@PAD@Z';
function openAVIDll(name: PChar): PVideoInfo; cdecl; external 'vidframe.dll' name '?openAVI@@YAPAUVideoInfo@@PAD@Z';
procedure closeVideoDll; cdecl; external 'vidframe.dll' name '?closeVideo@@YAXXZ';
function getFrameDll(frame: integer): PByteArray; cdecl; external 'vidframe.dll' name '?getFrame@@YAPAEH@Z';
function getWidthDLL: integer; cdecl; external 'vidframe.dll' name '?getWidth@@YAHXZ';
function getHeightDLL: integer; cdecl; external 'vidframe.dll' name '?getHeight@@YAHXZ';
function getFramecountDLL: integer; cdecl; external 'vidframe.dll' name '?getFramecount@@YAHXZ';
procedure initFrameBM;
begin
if frameBM <> nil then frameBM.Destroy;
frameBM := TBitMap.Create;
frameBM.Width := videoinfo.width;
frameBM.Height := videoinfo.height;
frameBM.PixelFormat := pf24bit;
isVideoOpen := True;
end;
procedure openDirectShow(name: String);
begin
videoinfo := openDirectShowDll( PChar(name) );
initFrameBM;
end;
procedure openAVI(name: String);
begin
videoinfo := openDirectShowDll( PChar(name) );
initFrameBM;
end;
procedure closeVideo;
begin
if frameBM <> nil then
begin
frameBM.Destroy;
frameBM := nil;
end;
videoinfo := nil;
if isVideoOpen then
begin
closeVideoDll;
isVideoOpen := False;
end;
end;
procedure getFrame(frame: integer);
var p, sl: PByteArray;
y: integer;
begin
p := getFrameDLL(frame);
for y := 0 to videoinfo.height-1 do
begin
sl := frameBM.ScanLine[videoinfo.height - y - 1];
move(p[y * videoinfo.width * 3], sl[0], videoinfo.width * 3);
end;
end;
function getWidth: integer;
begin
if videoinfo = nil then
getWidth := 0
else
getWidth := videoinfo.width;
end;
function getHeight: integer;
begin
if videoinfo = nil then
getHeight := 0
else
getHeight := videoinfo.height;
end;
function getFrameCount: integer;
begin
if videoinfo = nil then
getFrameCount := 0
else
getFrameCount := videoinfo.num_frames;
end;
function getFPS: float;
begin
if videoinfo = nil then
getFPS := 0.0
else
getFPS := videoinfo.fps_numerator / videoinfo.fps_denominator;
end;
begin
isVideoOpen := False;
videoinfo := nil;
frameBM := nil;
end.
Can anyone help me to translate these routines (especially the ones that access the dll) to Visual Basic? I've tried that, but my knowledge on VB and Delphi is still limited. Thanks in advance.
PS. On Aquaplaning's web page (http://aquaplaning.20m.com), you can find an example code on how to use this Delphi unit, in this file (http://aquaplaning.20m.com/vidframe_sources.zip).
unit vidframe;
interface
uses SysUtils, Graphics;
type
float = Double;
TMyColor = record
case Integer of
0: (c: TColor);
1: (r, g, b, x: byte);
2: (l: LongInt);
end;
TVideoInfo = record
width, height, // width=0 means no video
fps_numerator, fps_denominator, num_frames: integer;
pixel_type: word; // UNKNOWN=0, YUY2=2, BGR24=3 }
audio_samples_per_second, // 0 means no audio
num_audio_samples: integer;
stereo, sixteen_bit, field_based: boolean;
end;
PVideoInfo = ^TVideoInfo;
var videoInfo: PVideoInfo;
frameBM: TBitMap;
isVideoOpen: boolean;
// capsulated functions for delphi, recommended for use
procedure openDirectShow(name: String);
procedure openAVI(name: String);
procedure closeVideo;
procedure getFrame(frame: integer);
function getWidth: integer;
function getHeight: integer;
function getFrameCount: integer;
function getFPS: float;
// direct access to DLL function's
function openDirectShowDll(name: PChar): PVideoInfo; cdecl;
function openAVIDll(name: PChar): PVideoInfo; cdecl;
procedure closeVideoDll; cdecl;
function getFrameDll(frame: integer): PByteArray; cdecl;
function getWidthDLL: integer; cdecl;
function getHeightDLL: integer; cdecl;
function getFramecountDLL: integer; cdecl;
implementation
function openDirectShowDll(name: PChar): PVideoInfo; cdecl; external 'vidframe.dll' name '?openDirectShow@@YAPAUVideoInfo@@PAD@Z';
function openAVIDll(name: PChar): PVideoInfo; cdecl; external 'vidframe.dll' name '?openAVI@@YAPAUVideoInfo@@PAD@Z';
procedure closeVideoDll; cdecl; external 'vidframe.dll' name '?closeVideo@@YAXXZ';
function getFrameDll(frame: integer): PByteArray; cdecl; external 'vidframe.dll' name '?getFrame@@YAPAEH@Z';
function getWidthDLL: integer; cdecl; external 'vidframe.dll' name '?getWidth@@YAHXZ';
function getHeightDLL: integer; cdecl; external 'vidframe.dll' name '?getHeight@@YAHXZ';
function getFramecountDLL: integer; cdecl; external 'vidframe.dll' name '?getFramecount@@YAHXZ';
procedure initFrameBM;
begin
if frameBM <> nil then frameBM.Destroy;
frameBM := TBitMap.Create;
frameBM.Width := videoinfo.width;
frameBM.Height := videoinfo.height;
frameBM.PixelFormat := pf24bit;
isVideoOpen := True;
end;
procedure openDirectShow(name: String);
begin
videoinfo := openDirectShowDll( PChar(name) );
initFrameBM;
end;
procedure openAVI(name: String);
begin
videoinfo := openDirectShowDll( PChar(name) );
initFrameBM;
end;
procedure closeVideo;
begin
if frameBM <> nil then
begin
frameBM.Destroy;
frameBM := nil;
end;
videoinfo := nil;
if isVideoOpen then
begin
closeVideoDll;
isVideoOpen := False;
end;
end;
procedure getFrame(frame: integer);
var p, sl: PByteArray;
y: integer;
begin
p := getFrameDLL(frame);
for y := 0 to videoinfo.height-1 do
begin
sl := frameBM.ScanLine[videoinfo.height - y - 1];
move(p[y * videoinfo.width * 3], sl[0], videoinfo.width * 3);
end;
end;
function getWidth: integer;
begin
if videoinfo = nil then
getWidth := 0
else
getWidth := videoinfo.width;
end;
function getHeight: integer;
begin
if videoinfo = nil then
getHeight := 0
else
getHeight := videoinfo.height;
end;
function getFrameCount: integer;
begin
if videoinfo = nil then
getFrameCount := 0
else
getFrameCount := videoinfo.num_frames;
end;
function getFPS: float;
begin
if videoinfo = nil then
getFPS := 0.0
else
getFPS := videoinfo.fps_numerator / videoinfo.fps_denominator;
end;
begin
isVideoOpen := False;
videoinfo := nil;
frameBM := nil;
end.
Can anyone help me to translate these routines (especially the ones that access the dll) to Visual Basic? I've tried that, but my knowledge on VB and Delphi is still limited. Thanks in advance.
PS. On Aquaplaning's web page (http://aquaplaning.20m.com), you can find an example code on how to use this Delphi unit, in this file (http://aquaplaning.20m.com/vidframe_sources.zip).