VisualStudio 2017 C# (x86)にて
AForge.Video, Video.DirectShowなどをNuGetを使用してインストール(ver 2.2.5)、
USBカメラを使用して動画を撮影し、.mpgで保存したいです。
検索し調べているのですが、CodecをMJPGと設定しファイル拡張子.aviとして動画を保存している
サイトしかないです。
そこでお伺いしたいのですが、C#で.mpg で動画を保存する方法をお教えいただきたいです。
また、.aviで保存するしかないとしても現在codecをMJPGと設定すると例外が発生してしまいます。なぜcodecを設定すると例外が発生するのか?その解決法などアドバイスをいただきたく思います。
また、出力された例外文は
AForge.Video.VideoException: Failed creating compressed stream.
場所 AForge.Video.VFW.AVIWriter.Open(String fileName, Int32 width, Int32 Height)
場所 MainForm.RecButton_Click(Object sender, EventArgs e)
場所 プロジェクトファイル場所\Form1.cs
となります。
圧縮形式でAVIWriter.Openを行った際に例外が発生しているようです。
C#
1 //---- USBカメラ動画保存 ----// 2 AVIWriter usbVideoWriter = new AVIWriter(); 3 4 private void RecButton_Click(object sender, EventArgs e) 5 { 6 //撮影を開始する 7 videoSourcePlayer1.VideoSource.NewFrame += new NewFrameEventHandler(this.video_NewFrame); 8 //videoSourcePlayer1.VideoSource.Start(); 9 if (videoSourcePlayer1.VideoSource != null && !videoSourcePlayer1.VideoSource.IsRunning) 10 { 11 videoSourcePlayer1.Start(); 12 } 13 14 try 15 { 16 usbVideoWriter.FrameRate = 30; 17 usbVideoWriter.Codec = "MJPG"; 18 usbVideoWriter.Open(fileName: "USBVedeo.avi", width: 640, height: 480); 19 } 20 catch (Exception ex) 21 { 22 MessageBox.Show(ex.ToString(), "VideoWriterErr", MessageBoxButtons.OK, MessageBoxIcon.Error); 23 } 24 }
回答1件
あなたの回答
tips
プレビュー