从网络摄像头视频保存视频时出错c#

时间:2016-02-24 20:48:22

标签: c#-4.0

我需要一些错误的帮助..  错误2'c:\ Users \ anton \ OneDrive \Документы\ Visual Studio 2013 \ Projects \ WindowsFormsApplication4 \ packages \ Accord.Video.3.0.2 \ lib \ net45 \ Accord中存在'AForge.Video.NewFrameEventArgs'类型。 Video.dll'和'c:\ Users \ anton \ OneDrive \ Documents \ Visual Studio 2013 \ Projects \ WindowsFormsApplication4 \ packages \ AForge.Video.2.2.5 \ lib \ AForge.Video.dll'C:\ Users \ anton \ onedrive \ Documents \ visual studio 2013 \ Projects \ WindowsFormsApplication4 \ WindowsFormsApplication4 \ Form1.cs 50 42 WindowsFormsApplication4

this is my code:`



 using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using AForge.Video;
    using AForge.Video.DirectShow;
    using AForge.Video.FFMPEG;

    namespace WindowsFormsApplication4
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            private VideoCaptureDevice FinalVideo = null;
            private VideoCaptureDeviceForm captureDevice;
            private Bitmap video;
            private VideoFileWriter FileWriter = new VideoFileWriter();
            private SaveFileDialog saveAvi;
            private FilterInfoCollection webcam;
            private VideoCaptureDevice cam;
            private void Form1_Load(object sender, EventArgs e)
            {
                webcam = new FilterInfoCollection(FilterCategory.VideoInputDevice);
                foreach (FilterInfo VideoCaptureDevice in webcam)
                {
                    comboBox1.Items.Add(VideoCaptureDevice.Name);
                    comboBox1.SelectedIndex = 0;
                }
                pictureBox1.Anchor = (AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom);
                comboBox1.Anchor = (AnchorStyles.Bottom);
                button1.Anchor = (AnchorStyles.Bottom);
                button2.Anchor = (AnchorStyles.Bottom);
                button3.Anchor = (AnchorStyles.Bottom);
            }

            private void button1_Click(object sender, EventArgs e)
            {
                cam = new VideoCaptureDevice(webcam[comboBox1.SelectedIndex].MonikerString);
                cam.NewFrame += new NewFrameEventHandler(cam_NewFrame);
                cam.Start();
            }
            void cam_NewFrame(object sender, NewFrameEventArgs EventArgs)
            {
                Bitmap bit = (Bitmap)EventArgs.Frame.Clone();
                pictureBox1.Image = bit;

            }

            private void button3_Click(object sender, EventArgs e)
            {
                if (cam.IsRunning)
                {
                    cam.Stop();
                }
            }

            private void button2_Click(object sender, EventArgs e)
            {
                saveFileDialog1.InitialDirectory = @"C:\picture";
                saveFileDialog1.Filter = "Images|*.png;*.bmp;*.jpg";
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    pictureBox1.Image.Save(saveFileDialog1.FileName);
                }
            }

            private void button4_Click(object sender, EventArgs e)
            {
                saveAvi = new SaveFileDialog();
                saveAvi.Filter = "Avi Files (*.avi)|*.avi";
                if (saveAvi.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    int h = captureDevice.VideoDevice.VideoResolution.FrameSize.Height;
                    int w = captureDevice.VideoDevice.VideoResolution.FrameSize.Width;
                    FileWriter.Open(saveAvi.FileName, w, h, 25, VideoCodec.Default, 5000000);
                    FileWriter.WriteVideoFrame(video);

                    //AVIwriter.Open(saveAvi.FileName, w, h);

                    //FinalVideo = captureDevice.VideoDevice;
                    //FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame);
                    //FinalVideo.Start();
                }
            }

        }
    }

0 个答案:

没有答案