RT。
只写入视频时,生成的文件正常,
加上音频时,文件就不对了。
有没有哪位能提供个例子?
把示例代码贴上来,大家伙指点下const
  streamtypeAUDIO  = $73647561;
  streamtypeVIDEO  = $73646976;
var
  AcmWaveIn : TACMWaveIn;
  FOnData : Pointer;
  bStartWave : Boolean = False;
  GWaveStep : Integer = 0;
  WaveBuff : array of Byte;
  WaveBuffsize : Integer;procedure StartWave(parent : TWinControl;bufsize : LongInt; onData : TOnData);
  var format:TWaveFormatEx;
begin
  if Assigned(AcmWaveIn) then
    AcmWaveIn.Close
  else AcmWaveIn := TACMWaveIn.Create(parent);
  with format do
  begin
    wFormatTag := WAVE_FORMAT_PCM;
    nChannels := 1;
    nSamplesPerSec := 11025;
    wBitsPerSample := 8;
    nBlockAlign := nChannels * (wBitsPerSample div 8 );
    nAvgBytesPerSec := nSamplesPerSec * nBlockAlign;
    cbSize := 0;
  end;
  AcmWaveIn.Parent := parent;
  AcmWaveIn.OnData := onData;
  ACMWaveIn.BufferSize := bufsize;
  ACMWaveIn.Open(@format);
  bStartWave := True;
  SetLength(WaveBuff,bufsize);
  GWaveStep := 0;
  WaveBuffsize := bufsize;
end;procedure CloseWave;
begin
  if Assigned(AcmWaveIn) then
  begin
    AcmWaveIn.Close;
    FreeAndNil(AcmWaveIn);
  end;
  bStartWave := False;
  WaveBuff := nil;
end;function CreateAviFile(fname : string ; dwWidth , dwHeight  : Integer ; pf : TPixelFormat; var pFile : Pointer; var pStream : Pointer;var pAudioStream : Pointer) : Boolean;
  var VideoInfo,AudioInfo: TAVIStreamInfo;
      BitmapInfo: TBitmapInfoHeader;
      BitmapInfoSize : Cardinal;
      bitCount : Integer;
      waveFormat : tWAVEFORMATEX ;
begin
  Result := False;
  AVIFileInit;
  try
    case pf of
      pf1bit: bitCount := 1;
      pf4bit: bitCount := 4;
      pf8bit: bitCount := 8;
      pf15bit: bitCount := 15;
      pf16bit: bitCount := 16;
      pf24bit: bitCount := 24;
    end;
    if AVIFileOpen(pFile, PChar(fname), OF_WRITE or OF_CREATE or OF_SHARE_EXCLUSIVE, nil) <> 0 then Exit;
    FillChar(VideoInfo, sizeof(VideoInfo), 0);
    with VideoInfo do
    begin
      fccType := streamtypeVIDEO;
      fccHandler := 0;
      dwFlags := 0;
      dwSuggestedBufferSize := AlignBit(dwWidth, bitCount, 32) * Cardinal(abs(dwHeight));;
      rcFrame.Right := dwWidth;
      rcFrame.Bottom := dwHeight;
      dwScale := 1;
      dwRate := 15;
    end;
    if (AVIFileCreateStream(pFile, pStream, VideoInfo) <> 0) then Exit;    FillChar(AudioInfo, sizeof(AudioInfo), 0);
    with AudioInfo do
    begin
      fccType := streamtypeAUDIO;
      fccHandler := 0;
      dwFlags := 0;
      dwSuggestedBufferSize := 1024;
      dwScale := 1;
      dwRate := 15; //hz
      dwSampleSize := 1;
    end;
    if AVIFileCreateStream (pFile ,pAudioStream,AudioInfo) <> 0 then Exit;    FillChar(BitmapInfo, sizeof(TBitmapInfoHeader), 0);
    with BitmapInfo do
    begin
      biSize := SizeOf(TBitmapInfoHeader);
      biBitCount := bitCount;
      biWidth := dwWidth;
      biHeight := dwHeight;
      biPlanes := 1;
      biCompression := BI_RGB; // Always return data in RGB format
      biSizeImage := AlignBit(biWidth, biBitCount, 32) * Cardinal(abs(biHeight));
    end;
    if (AVIStreamSetFormat(pStream, 0, @BitmapInfo, sizeof(TBitmapInfoHeader)) <> 0) then  Exit;    with waveFormat do
    begin
      wFormatTag := WAVE_FORMAT_PCM;
      nChannels := 1;
      nSamplesPerSec := 11025;
      wBitsPerSample := 8;
      nBlockAlign := nChannels * (wBitsPerSample div 8 );
      nAvgBytesPerSec := nSamplesPerSec * nBlockAlign;
      cbSize := 0;
    end;
    if (AVIStreamSetFormat(pAudioStream, 0, @waveFormat, sizeof(waveFormat)) <> 0) then  Exit;
  finally  end;
  Result := True;
end;function WriteAviFile(pvideo : Pointer; var istep : Integer;pData : Pointer ; bufsize : Cardinal) : Boolean;
  var Dummy : Integer;
begin
  Result := AVIStreamWrite(pvideo, istep, 1, pData, bufsize, AVIIF_KEYFRAME, Dummy, Dummy) <> 0;
  Inc(istep);
end;function CloseAViFile(pFile,pStream : Pointer) : Boolean;
begin
  if pStream <> nil then
    AVIStreamRelease(pStream);
  if pFile <> nil then
    AVIFileRelease(pFile);
  AVIFileExit;
end;调用:
生成文件,开始录音
  fname := 'cc.avi';
  StartWave(Self,1024,OnData);
  CreateAviFile(fname,240,320,pf24bit,PAVIFile,PAVIStream,PWaveStream);
  Start := True;
  istep := 0;录音接收到的数据
procedure Tfrmmain.OnData(data: Pointer; size: Integer);
begin
  CopyMemory(@WaveBuff[0],data,size);
end;视频预览回调函数中写数据  if (PAVIFile <> nil) and (PAVIStream <> nil) and Start then
  begin
    WriteAviFile(PAVIStream,istep,bd.Scan0,bd.Height * bd.Stride);
    AVIStreamWrite(PWaveStream, GWaveStep, 1, @WaveBuff[0], 1024, AVIIF_KEYFRAME, Dummy, Dummy);
    inc(GWaveStep);
  end;