使用AForge的VideoFileWriter录制

时间:2013-10-23 13:19:12

标签: video aforge

我无法从网络摄像头录制视频。我尝试实现VideoFileWriter,但一直收到错误“无法找到指定的模块。(HRESULT异常:0x8007007E)”。每当我评论视频编写器时,一切都很好,但是当我尝试使用编写器将其记录到硬盘驱动器时,我得到了错误。 我希望这是一个容易解决的问题。以下是我的代码。

private FilterInfoCollection VideoCaptureDevices;
        private VideoCaptureDevice FinalVideoSource;
        Bitmap image;
        private VideoFileWriter writer;

        void VideoShow()
        {
            VideoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            FinalVideoSource = new VideoCaptureDevice(VideoCaptureDevices[0].MonikerString);
            FinalVideoSource.NewFrame += new NewFrameEventHandler(FinalVideoSource_NewFrame);
            FinalVideoSource.DesiredFrameRate = 15;
            FinalVideoSource.DesiredFrameSize = new Size(1280, 800);
            FinalVideoSource.Start();
        }

        void FinalVideoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            image = (Bitmap)eventArgs.Frame.Clone();
            pictureBox1.Image = image;
            writer.WriteVideoFrame(image);
        }

        public AForgeRecorder()
        {
            InitializeComponent();
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            writer = new VideoFileWriter();
            VideoShow();
            writer.Open(@"C:\testvvid.avi", 1280, 800, 15, VideoCodec.MPEG2, 128);
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            if (writer != null)
            {
                writer.Close();
            }
        }

提前致谢

1 个答案:

答案 0 :(得分:2)

很容易,Afrog VideoFileWriter使用FFMPEG.dll,所以下载FFMPEG zip,将所有5 dll从bin(avcodec-53.dll,.....等)复制到你的项目,右键单击你的项目,点击添加现有引用,选择所有dll,使其自己像往常一样复制, +你需要.net 3.5或更少。所以使用较低的框架工作