原码如下:unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, myVFW, ExtCtrls;type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FillBitmapStruct;
    procedure InitVideoCard;
    procedure InitCompressor;
    procedure CompressFrame(lpVHdr:PVIDEOHDR);  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;
  m_hWndCapture: Hwnd;
  m_CV:TCompVars;
  m_OutFormatSize,m_OutBufferSize:DWORD;
  m_InInfo:BITMAPINFO;
  m_pOutInfo:^BITMAPINFOHEADER;
  m_OutActSize:integer;
  bKeyFrame:Boolean;
  VideoBuf: Pointer;
  m_SampleNum:DWORD;type
  TVIDEO_DATA = packed record
  bKeyFrame:Boolean;
  nSampleNum:DWORD;
  nUsedSize:DWORD;
  Buf: array[0..8180] of BYTE;
end;
implementation{$R *.dfm}procedure TForm1.CompressFrame(lpVHdr:PVIDEOHDR);
var
VideoData:^TVIDEO_DATA;
begin
m_OutActSize:=m_InInfo.bmiHeader.biSizeImage;
VideoBuf:=ICSeqCompressFrame(@m_CV,0,lpVHdr.lpData,@bKeyFrame,@m_OutActSize);
GetMem(VideoData,sizeof(TVIDEO_DATA));
VideoData.bKeyFrame:=bKeyFrame;
Move(VideoBuf^, VideoData.Buf, 8180);
VideoData.nSampleNum:=m_SampleNum;
VideoData.nUsedSize:=m_OutActSize;
inc(m_SampleNum);
end;
function FrameCallBack(hwnde:Hwnd;lpvhdr:PVideoHdr):Dword;stdcall;
begin
if m_hWndCapture =0 then
begin
result:= 0;
Exit;
end;
Form1.CompressFrame(lpVHdr);
result:= 1;
end;procedure TForm1.InitVideoCard;
begin
m_hWndCapture:=capCreateCaptureWindow('Capture Window',WS_VISIBLE or WS_CHILD,0,0,320,240,Panel1.Handle,1);
capDriverConnect(m_hWndCapture,0);
//set the video format
capSetVideoFormat(m_hWndCapture,@m_InInfo,sizeof(BITMAPINFO));capPreviewRate(m_hWndCapture,40);
//capDlgVideoFormat(m_hWndCapture);
capPreview(m_hWndCapture,TRUE);
capSetCallbackOnFrame(m_hWndCapture,FrameCallBack);
end;
procedure TForm1.FillBitmapStruct;
beginFillChar(m_InInfo.bmiHeader, SizeOf(TBitmapInfoHeader), 0);with m_InInfo.bmiHeader do
begin
biBitCount := 24;
biCompression := BI_RGB;
biHeight := 240;
biPlanes := 1;
biSize := SizeOf(TBitmapInfoHeader);
biWidth := 320;
end;end;procedure TForm1.InitCompressor;
beginICCompressorChoose(0,0,nil,nil,@m_CV,'Choose a Compressor');
//FillChar(m_CV, SizeOf(m_CV), 0);m_CV.dwFlags:=ICMF_COMPVARS_VALID;
m_CV.cbSize:=sizeof(m_CV);
m_CV.cbState:=0;
m_CV.fccHandler:=mmioFOURCC('d','i','v','x');
m_CV.fccType:=ICTYPE_VIDEO;
m_CV.hic:=ICOpen(ICTYPE_VIDEO,mmioFOURCC('d','i','v','x'),ICMODE_COMPRESS);
m_CV.lDataRate:=780;
m_CV.lFrame:=0;
m_CV.lKey:=15;
m_CV.lKeyCount:=0;
m_CV.lpbiIn:=nil;
m_CV.lpBitsOut:=nil;
m_CV.lpBitsPrev:=nil;
m_CV.lpState:=nil;
m_CV.lQ:=0;if m_CV.hic<>0 then
begin
m_OutFormatSize:=ICCompressGetFormatSize(m_CV.hic,@m_InInfo);
GetMem(m_pOutInfo,m_OutFormatSize);
ICCompressGetFormat(m_CV.hic,@m_InInfo,@m_pOutInfo);
m_OutBufferSize:=ICCompressGetSize(m_CV.hic,@m_InInfo,@m_pOutInfo);
ICSeqCompressFrameStart(@m_CV,@m_InInfo);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
FillBitmapStruct;
InitVideoCard;
InitCompressor;
end;
end.