下面的代码是我在网上找到的,但运行有问题
type  VideoData=record    buf:array[0..8079] of byte; //压缩后的视频数据    Num:integer;//帧数据过大时,分几个数据包发送,数据包在这一帧中的编号    IsLast:boolean;//是否是这一帧的最后一个数据包end;定义全局变量:VarFCV: TCOMPVARS;//帧压缩结构FInInfo: TBitmapInfo;//压缩时输入结构FOutInfo: TBitmapInfo;//压缩时输出结构FoutActSize: DWORD;//压缩后帧数据的大小Buffer:^byte; //压缩后帧数据地址Buf: array of Byte;// 压缩后帧数据主要代码://填充BMP头结构procedure TForm1.FillBitmapStruc; begin  FillChar(FInInfo.bmiHeader, SizeOf(TBitmapInfoHeader), 0);  with FInInfo.bmiHeader do  begin        biBitCount := 24;    biCompression := BI_RGB;    biHeight := 240;    biPlanes := 1;    biSize := SizeOf(TBitmapInfoHeader);    biWidth := 320;  end;end;//初始化压缩引擎procedure TForm1.InitCompressor; begin  FillChar(FCV, SizeOf(FCV), 0);  with FCV do  begin    dwFlags := ICMF_COMPVARS_VALID;    cbSize := SizeOf(FCV);    fccHandler := mmioFOURCC('d','i','v','x');   //选择压缩引擎,这里选择divx    fccType := ICTYPE_VIDEO;    hic := ICOpen(ICTYPE_VIDEO,fccHandler, ICMODE_COMPRESS);    lDataRate := 780;    lKey := 15;    lQ :=dword(ICQUALITY_DEFAULT);    if hic <> 0 then    begin      FillChar(FOutInfo, SizeOf(FOutInfo), 0);      ICCompressGetFormat(hic, @FInInfo, @FOutInfo);      FInInfo.bmiHeader.biCompression:=BI_RGB;      FOutInfo.bmiHeader.biCompression:=fccHandler;      ICSeqCompressFrameStart(@FCV, @FInInfo);    end;  end;end;//FormOnShow事件procedure TForm1.FormShow(Sender: TObject);begin  FillBitmapStruc;  InitCompressor; //设置VideoCap1的相关属性  VideoCap1.DriverIndex:=0;VideoCap1.CapToFile:=false;  VideoCap1.DriverOpen:=true;  videocap1.VideoPreview:=true;end;//StartVideoOnClick事件procedure TForm1.StartVideoClick(Sender: TObject);beginVideoCap1.StartCapture;end;// VideoCap1OnVideoStream事件procedure TForm1.VideoCap1VideoStream(sender: TObject; lpVhdr: PVIDEOHDR);var KeyFrame:boolean;  MyVideo:VideoData;  i:integer;begin  if CheckSend.Checked then  begin    FOutActSize:=0;    MyVideo.Num:=0;    //压缩帧数据    Buffer:= ICSeqCompressFrame(@FCV, 0, lpVHdr^.lpData, @KeyFrame, @FOutActSize);    SetLength(buf,FOutActSize);    Move(Buffer^, Buf[0], FOutActSize);    //当帧数据太大时,分几个数据包发送    while FOutActSize>8080 do    begin      MyVideo.Num:=MyVideo.Num+1;      MyVideo.IsLast:=false;      for i:=0 to 8079 do      begin       MyVideo.buf[i]:= buf[(MyVideo.Num-1)*8080+i];      end;      FOutActSize:=FOutActSize-8080;      // 向客户端发送数据包VideoSender.SendBuffer(CilentIP.text,strtoint(ClientPort.text),MyVideo,sizeof(MyVideo));    end;    if FOutActSize<8080 then    begin      MyVideo.Num:=MyVideo.Num+1;      MyVideo.IsLast:=true; //当前帧最后一个数据包      for i:=0 to FOutActSize  do      begin        MyVideo.buf[i]:= buf[(MyVideo.Num-1)*8080+i];      end;     //向客户端发送数据包VideoSender.SendBuffer(CilentIP.text,strtoint(ClientPort.text),MyVideo,sizeof(MyVideo));    end;  end;  application.ProcessMessages;end;//StopVideoOnClick事件procedure TForm1. StopVideoClick (Sender: TObject);beginVideoCap1.StopCapture;end;//FormOnClose事件procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);begin  if FCV.hic <> 0 then  begin    ICSeqCompressFrameEnd(@FCV);    ICCompressorFree(@FCV);    ICClose(FCV.hic);  end;end;
    Buffer:= ICSeqCompressFrame(@FCV, 0, lpVHdr^.lpData, @KeyFrame, @FOutActSize);
这一句返回的是空值。是由什么原因造成的,
网址是
http://www.comprg.com.cn/detail.asp?hw_id=7829

解决方案 »

  1.   

    压缩成mp4格式,2小时才70M,而且清晰度不错。
      

  2.   

    客户端收不到不是压缩的问题,是你传输的问题。
    你要检查,你运行这段代码的电脑上有没有divx的编码器。
    就是这段话: fccHandler := mmioFOURCC('d','i','v','x');   //选择压缩引擎,这里选择divx
    如果没有相应的编码器,是不会压缩成功的。
    先把压缩的问题解决了,存放在本地,能压缩成功,能播放,再进行网络传输。
    压缩成mp4的确实是小,但是你要找到合适的编码器,最好在网上找现成的,
    看免费的源码的话,这个玩意很费时间的。
      

  3.   

    重複的貼子
    我在您的這篇貼子中有作詳細回答,請仔細參考:http://topic.csdn.net/u/20100908/00/bfd04f23-7fb7-481f-8b91-c8350379fe7c.html
      

  4.   

    基於視頻傳輸的demo程序已發送到[email protected],請查收!PS:(此DEMO程序是我使用DSPACK組件給公司開發的視頻會議系統中分享出了視頻傳輸代碼)目前只發給你了EXE可執行程序,先看一下效果;如有任何問題,請與我聯繫
      

  5.   

    虽然已经结贴了,但是还是说说,可以使用微软公司免费的mp4压缩编码器。
    使用Avi格式,微软公司有类库的。wvf