我做了一个录制AVI文件并保存的程序,为什么执行到设置流格式,也就是这句会出错AVIStreamSetFormat。有时要执行好几次才可以录制保存成功。请各位高手帮忙。
var
  status:HVSTATUS;
  ppBuf:Array[1..1] of pChar; //保存图像的缓冲区列表
  pPointer:longWord; //指向缓冲区列表的指针
  wVer:WORD;
  hr:HRESULT;
  bRVal:boolean;  strhdr:PAVISTREAMINFOA ; //AVI文件信息
  opts:PAVICOMPRESSOPTIONS ;
  FileName:String;
beginbRVal := TRUE;
  status := STATUS_OK;
  hr := S_OK;
  
  wVer := HIWORD(VideoForWindowsVersion());
if ( (wVer >= 266)) then // oops, we are too old, blow out of here // if 2
  begin
AVIFileInit();
  
  FileName:='D:\'+formatdatetime('yyyymmddhhnnss',now)+'.avi';
// 创建AVI文件 // returned file pointer // file name // mode to open file with
hr := AVIFileOpen(m_pFile, Pchar(FileName), OF_WRITE or OF_CREATE,nil); // use handler determinedif (hr <> AVIERR_OK) then // if 3
  begin
bRVal := FALSE;
  end
else
  begin
  new(strhdr);
strhdr.fccType := streamtypeVIDEO;// stream type
strhdr.fccHandler := 0; // 808810089
strhdr.dwScale := 1;
strhdr.dwRate := 15; // rate fps
strhdr.dwSuggestedBufferSize := HV_Width * HV_Height * 3;
SetRect(strhdr.rcFrame, 0, 0, HV_Width, HV_Height);// rectangle for stream
// And create the stream; // file pointer // returned stream pointer   
hr := AVIFileCreateStream(m_pFile,m_ps,strhdr); // stream header
if (hr <> AVIERR_OK) then // if 4
  begin
bRVal := FALSE;
  end
else
  begin
  new(opts);
  (* opts.fccType := StreamTypeVIDEO;
  opts.fccHandler := 808810089; // 0
  opts.dwKeyFrameEvery :=0;
  opts.dwQuality :=8500;
  opts.dwBytesPerSecond :=0;
  opts.dwFlags :=8;
  opts.lpFormat :=nil;
  opts.cbFormat :=0;
  opts.cbParms :=48;
  opts.dwInterleaveEvery := 0;   
  *)
if (not AVISaveOptions(FrmMain.Handle, 0, 1, m_ps, opts)) then // if 5
  begin
bRVal := FALSE;
  end
else
  begin
hr := AVIMakeCompressedStream(m_psCompressed, m_ps, opts, nil);
if (hr <> AVIERR_OK) then // if 6
  begin
bRVal := FALSE;
  end
  else // format size
  begin // stream format
  try
  hr := AVIStreamSetFormat(m_psCompressed,0,m_pBmpInfo,sizeof(BITMAPINFOHEADER));
    
  if (hr <> AVIERR_OK) then
bRVal := FALSE;
  except
  end;
end; // end if 6
end; // end if 5
end; // end if 4
end; // end if 3
end; // end if 2