嘿我正在尝试保存网络摄像头的视频并将其保存为未压缩。但是,无论何时单击保存按钮,应用程序都会冻结,直到保存完成。我将不胜感激任何建议。我正在使用托管代码“FLea 3”的托管代码(来自Points灰色)
private void button1_Click(object sender, EventArgs e)
{
uint k_numImages = 100;
// ManagedAVIRecorder aviRecorder = new ManagedAVIRecorder();
// List<ManagedImage> imageList = new List<ManagedImage>();
List<ManagedImage> imageList = new List<ManagedImage>();
ManagedImage rawImage = new ManagedImage(m_rawImage);
for (int imageCnt = 0; imageCnt < k_numImages; imageCnt++)
// while (m_grabImages == true)
{
m_camera.RetrieveBuffer(rawImage);
ManagedImage tempImage = new ManagedImage(rawImage);
imageList.Add(tempImage);
}
if (m_grabImages==true)
{
//Encoding bit
string aviFileName;
AviOption option = new AviOption();
option.frameRate = 24;
aviFileName = String.Format("SaveCSharp-aviuncompressed");
aviRecorder.AVIOpen(aviFileName, option);
// aviFileName = String.Format("SaveCSharp-h264");
// H264Option option = new H264Option();
// option.frameRate = 24;
// option.bitrate = 20000000;
// option.height = Convert.ToInt32(m_rawImage.rows);
// option.width = Convert.ToInt32(m_rawImage.cols);
// aviRecorder.AVIOpen(aviFileName, option);
for (int imageCnt = 0; imageCnt < imageList.Count; imageCnt++)
{
aviRecorder.AVIAppend(imageList[imageCnt]);
}
aviRecorder.AVIClose();
}
}
private void button2_Click(object sender, EventArgs e)
{
// aviRecorder.AVIClose();
}
}
}
答案 0 :(得分:2)
您很可能希望在另一个线程上运行记录操作。但是,这会变得有点棘手,因为你必须来回传递消息到记录器线程,告诉它何时停止,例如。