2014-04-23 41 views
0

我想保存从网络摄像头捕获到本地磁盘的视频。我写代码显示网络摄像头,但它不能保存到本地磁盘。错误是创建压缩流失败。。我应该在这里做什么?Aforge视频捕获并保存在本地磁盘

  writer = new AVIWriter("wmv3"); 
      writer.FrameRate = 30; 
      writer.Open("video.avi", Convert.ToInt32(640), Convert.ToInt32(480)); // ERROR İS HERE **Failed creating compressed stream.** 

      //Create NewFrame event handler 
      //(This one triggers every time a new frame/image is captured 
      videoSource.NewFrame += new AForge.Video.NewFrameEventHandler(videoSource_NewFrame); 

      //Start recording 
      videoSource.Start(); 


     } 
    }  
    void videoSource_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs) 
    { 

     //Cast the frame as Bitmap object and don't forget to use ".Clone()" otherwise 
     //you'll probably get access violation exceptions 
     pictureBoxVideo.BackgroundImage = (Bitmap)eventArgs.Frame.Clone(); 
     writer.AddFrame((Bitmap)eventArgs.Frame.Clone()); 
    } 
+0

你有你的电脑上安装了WMV3编码器?我可能会误解,但您应该考虑从[这里](http://www.microsoft.com/expression/eng/#encoder)下载并安装Microsoft Expression Encoder。 –

+0

我已安装,但我如何编码Microsoft Expression Encoder与Visual Studio 2012? –

回答

0

你有没有考虑过你的摄像头流的大小?我也遇到同样的问题。我知道你将视频大小设置为640和480,但是来自摄像头的视频流大小(我猜)绝不会相同。我也猜你会将你的容器(如picturebox或imagebox)设置为640和480,但这并不意味着视频流会相同。我使用savedialog来检查从我的摄像头发出的视频流,并猜测是什么?大小将是(648,486)。谁会设置这样一个奇怪的数字集?但我将我的代码设置为:

writer.Open(“video.avi”,Convert.ToInt32(648),Convert.ToInt32(486));

它工作正常!

我不知道你的代码的其余部分的正确与否,但我敢肯定,我的错误是在集大小的:)