以下是源代码:unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,VFW, IdBaseComponent, IdComponent, IdUDPBase,
IdUDPServer, IdUDPClient,IdSocketHandle, IdAntiFreezeBase, IdAntiFreeze;type
TVIDEO_DATA = packed record
bKeyFrame : bool;
nSampleNum : DWORD;
nUsedSize : DWORD;
Buf : Array[0..4084-1] of byte;
end;
TForm1 = class(TForm)
PnV1: TPanel;
PnV2: TPanel;
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
IdUDPClient1: TIdUDPClient;
IdUDPServer1: TIdUDPServer;
IdAntiFreeze1: TIdAntiFreeze;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
dc:HDC;
hdd:HDRAWDIB;
BmpInfo,BmpInfo1:BITMAPINFO;
hWndc:Thandle; DataPoint:^byte;
DataPoint1:^byte;
// DataPoint:Pchar;
OutFormatSize:dword;
BmpOutInfo:^BITMAPINFO;
CapVar:TCOMPVARS;
OutBufferSize:DWORD;
function InitCaptureParams : boolean; end;var
Form1: TForm1;
function FrameCallBack(hWnd:HWND;lpVHdr:PVIDEOHDR):DWORD;stdcall;
implementation{$R *.dfm}{ TForm1 }function Tform1.InitCaptureParams : boolean;begin
result := False;
zeromemory(@CapVar,sizeof(TCOMPVARS));
CapVar.cbSize:=sizeof(CapVar); //必须指定cbSize为TCOMPVARS结构大小
CapVar.dwFlags:=ICMF_COMPVARS_VALID;
CapVar.cbState:=0;
CapVar.fccHandler:=859189837;
CapVar.fccType:=ICTYPE_VIDEO;
CapVar.hic:=ICOpen(ICTYPE_VIDEO, CapVar.fccHandler, ICMODE_COMPRESS);
if (CapVar.hic>0) then
begin
OutFormatSize:=ICCompressGetFormatSize(CapVar.hic,@BmpInfo);
getmem(BmpOutInfo,OutFormatSize);
ICCompressGetFormat(CapVar.hic,@BmpInfo.bmiHeader,@BmpOutInfo.bmiHeader);
OutBufferSize:=ICCompressGetSize(CapVar.hic,@BmpInfo.bmiHeader,@BmpOutInfo.bmiHeader);
ICSeqCompressFrameStart(@CapVar,@BmpInfo);
result := True;
end
else
begin
Showmessage('请先安装视频压缩编码器');
Exit;
end
end;function FrameCallBack(hWnd:HWND;lpVHdr:PVIDEOHDR):DWORD;stdcall;
var
bKeyFrame : BOOL ;
Buf : PBYTE;
VideoData : TVIDEO_DATA;
OutActSize : dword;
begin
OutActSize := form1.BmpOutInfo.bmiHeader.biSizeImage;
Buf := ICSeqCompressFrame(@form1.CapVar,0,lpVHdr.lpData,@bKeyFrame,@OutActSize);
result := 0;end;procedure TForm1.Button1Click(Sender: TObject);
begin
hWndC:=capCreateCaptureWindowA('Capdfture Window',WS_CHILD or WS_VISIBLE,PnV1.Left,PnV1.Top,PnV1.Width,PnV1.Height,form1.Handle,0);
if hWndC = 0 then exit; capDriverConnect(hWndC,0); //连接摄像头设备
capDlgVideoFormat(hWndC); //显示视频设置对话框,进行配置视频的大小、颜色位数等。
capGetVideoFormat(hWndC,@BmpInfo,sizeof(BITMAPINFO)); //取得视频图像数据头,后面压缩时需要用到
capPreviewRate(hWndC, 33); //设置预览视频的频率,33代表第秒30帧。
capPreview(hWndC, TRUE);
capSetCallbackOnFrame(hWndC,FrameCallBack);
InitCaptureParams;
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,VFW, IdBaseComponent, IdComponent, IdUDPBase,
IdUDPServer, IdUDPClient,IdSocketHandle, IdAntiFreezeBase, IdAntiFreeze;type
TVIDEO_DATA = packed record
bKeyFrame : bool;
nSampleNum : DWORD;
nUsedSize : DWORD;
Buf : Array[0..4084-1] of byte;
end;
TForm1 = class(TForm)
PnV1: TPanel;
PnV2: TPanel;
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
IdUDPClient1: TIdUDPClient;
IdUDPServer1: TIdUDPServer;
IdAntiFreeze1: TIdAntiFreeze;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
dc:HDC;
hdd:HDRAWDIB;
BmpInfo,BmpInfo1:BITMAPINFO;
hWndc:Thandle; DataPoint:^byte;
DataPoint1:^byte;
// DataPoint:Pchar;
OutFormatSize:dword;
BmpOutInfo:^BITMAPINFO;
CapVar:TCOMPVARS;
OutBufferSize:DWORD;
function InitCaptureParams : boolean; end;var
Form1: TForm1;
function FrameCallBack(hWnd:HWND;lpVHdr:PVIDEOHDR):DWORD;stdcall;
implementation{$R *.dfm}{ TForm1 }function Tform1.InitCaptureParams : boolean;begin
result := False;
zeromemory(@CapVar,sizeof(TCOMPVARS));
CapVar.cbSize:=sizeof(CapVar); //必须指定cbSize为TCOMPVARS结构大小
CapVar.dwFlags:=ICMF_COMPVARS_VALID;
CapVar.cbState:=0;
CapVar.fccHandler:=859189837;
CapVar.fccType:=ICTYPE_VIDEO;
CapVar.hic:=ICOpen(ICTYPE_VIDEO, CapVar.fccHandler, ICMODE_COMPRESS);
if (CapVar.hic>0) then
begin
OutFormatSize:=ICCompressGetFormatSize(CapVar.hic,@BmpInfo);
getmem(BmpOutInfo,OutFormatSize);
ICCompressGetFormat(CapVar.hic,@BmpInfo.bmiHeader,@BmpOutInfo.bmiHeader);
OutBufferSize:=ICCompressGetSize(CapVar.hic,@BmpInfo.bmiHeader,@BmpOutInfo.bmiHeader);
ICSeqCompressFrameStart(@CapVar,@BmpInfo);
result := True;
end
else
begin
Showmessage('请先安装视频压缩编码器');
Exit;
end
end;function FrameCallBack(hWnd:HWND;lpVHdr:PVIDEOHDR):DWORD;stdcall;
var
bKeyFrame : BOOL ;
Buf : PBYTE;
VideoData : TVIDEO_DATA;
OutActSize : dword;
begin
OutActSize := form1.BmpOutInfo.bmiHeader.biSizeImage;
Buf := ICSeqCompressFrame(@form1.CapVar,0,lpVHdr.lpData,@bKeyFrame,@OutActSize);
result := 0;end;procedure TForm1.Button1Click(Sender: TObject);
begin
hWndC:=capCreateCaptureWindowA('Capdfture Window',WS_CHILD or WS_VISIBLE,PnV1.Left,PnV1.Top,PnV1.Width,PnV1.Height,form1.Handle,0);
if hWndC = 0 then exit; capDriverConnect(hWndC,0); //连接摄像头设备
capDlgVideoFormat(hWndC); //显示视频设置对话框,进行配置视频的大小、颜色位数等。
capGetVideoFormat(hWndC,@BmpInfo,sizeof(BITMAPINFO)); //取得视频图像数据头,后面压缩时需要用到
capPreviewRate(hWndC, 33); //设置预览视频的频率,33代表第秒30帧。
capPreview(hWndC, TRUE);
capSetCallbackOnFrame(hWndC,FrameCallBack);
InitCaptureParams;
end;end.
解决方案 »
- 急求 搞了二十小时了 Delphi 双击关闭pagecontrol中的一个分页内存报错
- 关于数据更新的疑问!
- DLL入口问题。(50分)
- 有没有谁知道如何用delphi实现将数据库的备份文件进行压缩?
- memo如何象RichEdit一样获取光标选中的字符呢??
- 熟悉oracle的大虾请进,很菜的问题
- delphi关闭多个窗体的问题
- build with runtime packages问题
- 请问各位高手们,how to 在delphi中实现把unicode纯文本转成ani纯文本?
- 急,急,急用datetimepicker控件控制时间段?
- 关于TidSMTP开发邮件问题(delphi自带的案例)
- 征求indy控件IndyTcpClient接收数据问题
那里有不少好东西,压缩算法自己写好了