我做了一个录制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;
begin bRVal := 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 determined        if (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

解决方案 »

  1.   

    function     AVIStreamSetFormat(pavi:   PAVIStream;   lPos:   LONG;   lpFormat:   pointer;   cbFormat:   LONG):   HResult;   stdcall;  
      

  2.   

    向文件写入一个数据流  我们可以通过AVIFileCreateStream函数来在一个新文件或者已经存在的文件中创建一个数据流。这个函数根据AVISTREAMINFO结构定义了新的数据流,并为新的数据流创建一个接口,返回接口的指针。  在写入新的数据前,一定要指定流的格式信息,通过AVIStreamSetFormat函数,当设置一个视频流的时候,一定要使用BIMAPINFO结构来设置,音频就用WAVEFORMAT。  然后我们就可以通过AVIStreamWrite函数将我们的多媒体数据写入数据流了。这个函数将应用程序提供的内存数据复制到指定的流。缺省的avi handler将数据写入流的最后。  如果你有其他额外的信息需要写入流,你可以调用AVIFileWriteData或者AVIStreamWriteData,最后记得在完成数据写入后,要调用AVIStreamRelease。
      

  3.   

    to kye_jufei
     我调试了,是这个函数AVIStreamSetFormat有问题,它的返回值是一个-276783282,正常应该是0,但有时执行多次又可以了,里面的参数都没有问题,还没到AVIStreamWrite函数呢,在设定流格式时出错,不知道是哪里出问题了。。请kye_jufei帮忙,你的QQ是多少??想和你交流一下。
      

  4.   

    to hongqi162  
    (失踪的月亮) 我用的是32位的图。你的QQ是多少,能否远程帮我看一下。多谢了。。
      

  5.   

    to hongqi162   
    (失踪的月亮)  我用的是32位的图。你的QQ是多少,能否远程帮我看一下。多谢了。。
      

  6.   

    to hongqi162   
    (失踪的月亮)   我用的是32位的图。你的QQ是多少,能否远程帮我看一下。多谢了。。
      

  7.   

    AVIStreamSetFormat(m_psCompressed,0,m_pBmpInfo,sizeof(BITMAPINFOHEADER));
        
    这里面的sizeof(BITMAPINFOHEADER),提前输出一下看是多少
      

  8.   

    to theforever (赵亮,碧海情天,断水寒刀)sizeof(BITMAPINFOHEADER)的值是40.你有QQ吗,想和你交流一下。
      

  9.   

    to theforever (赵亮,碧海情天,断水寒刀)sizeof(BITMAPINFOHEADER)的值是40.你有QQ吗,想和你交流一下。
      

  10.   

    to theforever (赵亮,碧海情天,断水寒刀)sizeof(BITMAPINFOHEADER)的值是40.你有QQ吗,想和你交流一下。
      

  11.   

    to theforever (赵亮,碧海情天,断水寒刀)sizeof(BITMAPINFOHEADER)的值是40.你有QQ吗,想和你交流一下。