2014-04-23 39 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));

它工作正常!

我不知道你的代碼的其餘部分的正確與否,但我敢肯定,我的錯誤是在集大小的:)