本來想玩openCV做商品辨識能力的智慧型倉儲,不過公司比較想做錄影存證,沒差,都好玩啦
不過在存放webcam的畫面進入mp4時,出現了System.ArgumentException
===========================================
using Accord.Video.FFMPEG;
using Accord.Controls;
using Accord.Video;
using Accord.Video.DirectShow;
.....
....
...
using Accord.Video.FFMPEG;
using Accord.Controls;
using Accord.Video;
using Accord.Video.DirectShow;
.....
....
...
VideoFileWriter fileWriter = new VideoFileWriter();
....
private void Video_NewFrame1(object sender, NewFrameEventArgs eventArgs) {
video = (Bitmap)eventArgs.Frame.Clone();
picShowImg.Image = (Bitmap)eventArgs.Frame.Clone();
if (isRecording) fileWriter.WriteVideoFrame(video);
}
.....
.....
....
void bgnSaveVideo(){
int h = 1024;
int w = 768;
string fileName = "d:\\" + System.DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".mp4";
fileWriter.Open(fileName, w, h, 24, VideoCodec.MPEG4, 50000000);
fileWriter.WriteVideoFrame(video); <------這時發生錯誤!!
}
============================================
查了很久,試了好幾次才知道原因:長寬不是自己高興多少就多少,而是要看當時frame的bitmap長寬多少,才能用WriteVideoFrame
=======以下是正確的寫法========
int h = video.Height;
int w = video.Width;
string fileName = "d:\\" + System.DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".mp4";
fileWriter.Open(fileName, w, h, 24, VideoCodec.MPEG4, 50000000);
fileWriter.WriteVideoFrame(video); <------這時就過關了!!
=============================
...
...
os:應該沒人犯這樣的錯吧.網路上一直找不到相關的案例....
沒有留言:
張貼留言