Prelude:
我打算用这个作为序言,我在工作时间里一直在学习C#,并且我一直在盯着代码坚持两天试图解决这个问题 . 我正在开发一些软件,用于通过USB连接到标准台式PC的可视化器,软件检测捕获设备并使用新帧事件将帧加载到位图中,然后将其显示在“图片框”中作为直播视频流 . 它所处的问题是试图加强记录流并保存到文件的能力,最好是WMV或压缩的AVI .
What's been tried:
我考虑过并研究过以下内容:
SharpAVI - 似乎无法正常压缩或保存帧,因为它似乎主要是查看现有的AVI文件 .
AForge.Video.VFW - 由于对将要使用该软件的个人的用户区域的限制,可以创建AVI文件但是太大而无法使用 .
AForge.Video.FFMPEG - 再次由于使用这个软件的人的考虑,我可以__40726_ s与可执行文件坐在输出文件夹中,不幸的是这个特定的DLL不能使用Costura Fody正确编译 .
AVIFile库包装器(来自代码项目) - 似乎无法通过新帧事件从Bitmaps正确压缩流 .
DirectShow - 似乎使用C,不幸的是,此时超出了我的技能水平 .
The Relevant Code Snippets:
目前的参考文献:
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Resources;
using System.Drawing.Imaging;
using System.IO;
//Aforge Video DLL's
using AForge.Video;
using AForge.Video.VFW;
using AForge.Video.DirectShow;
//Aforge Image DLL's
using AForge.Imaging;
using AForge.Imaging.Formats;
using AForge.Imaging.Filters;
//AviLibrary
using AviFile;
全局变量:
#region Global Variables
private FilterInfoCollection CaptureDevice; // list of available devices
private VideoCaptureDevice videoSource;
public System.Drawing.Image CapturedImage;
bool toggleMic = false;
bool toggleRec = false;
//aforge
AVIWriter aviWriter;
Bitmap image;
#endregion
显示流的代码
#region Displays the Stream
void videoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
picBoxStream.SizeMode = PictureBoxSizeMode.Zoom;
picBoxStream.Image = (Bitmap)eventArgs.Frame.Clone();// clones the bitmap
if (toggleRec == true)
{
image = (Bitmap)eventArgs.Frame.Clone();
aviWriter.AddFrame(image);
}
}
#endregion
当前的录制流代码
#region Record Button
private void btnRecord_Click(object sender, EventArgs e)
{
if (toggleRec == false)
{
saveAVI = new SaveFileDialog();
saveAVI.Filter = "AVI Files (*.avi)|*.avi";
if (saveAVI.ShowDialog() == DialogResult.OK)
{
aviWriter = new AVIWriter();
aviWriter.Open(saveAVI.FileName, 1280, 720);
toggleRec = true;
Label lblRec = new Label();
}
}
else if (toggleRec == true)
{
aviWriter.Close();
toggleRec = false;
}
}
#endregion
如果上面的代码看起来不太正确,我会进行代理,我一直在交换,更改和重新编码这三个部分以便找到一个有效的组合 . 这意味着它相当凌乱但我没有看到清理它的重点,直到我的代码工作 . 说实话,你能提供的任何帮助都会得到很好的回报,即使这是我想要做的事情也是无法完成的 .
先感谢您 .
EDIT: PostScript:
我将在星期一到星期五积极工作,所以如果我做出任何突破,我会相应地更新这个问题,这似乎是经常回答的问题,所以希望我们能够克服这些问题 .
2 回答
和我刚刚解决的问题一样:)这里是我的代码如何使用AviFile库dll制作avi文件:)