AForge.net视频录制


最最简单的AForge.net视频录制示例,没有录制声音的功能,只有视频
资源截图
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AForge.Video.DirectShow;
using AForge.Video.FFMPEG;
using System.Diagnostics;
using AForge.Video;
using System.IO;

namespace OCVideoApplication
{
    public partial class Form1 : Form
    {
        private FilterInfoCollection videoDevices;
        private VideoCaptureDevice videoSource;

        private bool stopREC = true;
        private bool createNewFile = true;

        private string videoFileFullPath = string.Empty; //视频文件全路径
        private string imageFileFullPath = string.Empty; //图像文件全路径
        private string videoPath = @“D:OCVideoVideo“; //视频文件路径
        private string imagePath = @“D:OCVideoImages“; //图像文件路径
        private string videoFileName = string.Empty; //视频文件名
        private string imageFileName = string.Empty; //图像文件名
        private string drawDate = string.Empty;
        private VideoFileWriter videoWriter = null;
        private DateTime dt;
        public delegate void MyInvoke(); //定义一个委托方法

        string g_s_AutoSavePath = AppDomain.CurrentDomain.baseDirectory + “Capture\“;
        object objLock = new object(); //定义一个对象的锁
        int frameRate = 20; //默认帧率
        private Stopwatch stopWatch = null;
        IVideoSource iVideoSource = null;
        public Form1()
        {
            InitializeComponent();
            try
            {
                videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
                if (videoDevices.Count == 0)
                {
                    MessageBox.Show(“no cameras found“);
                    throw new Exception();
                }
                else {
                    VideoCaptureDevice videoSource1 = new VideoCaptureDevice(videoDevices[0].MonikerString);
                    //videoSource1.DesiredframeRate = 10;
                    videoSourcePlayer1.VideoSource = videoSource1;
                    videoSourcePlayer1.Start();
                }
            }
            catch
            {
                
            }
        }

        private void videoSourcePlayer1_Newframe(object sender ref Bitmap image)
        {
            using (Graphics g = Graphics.FromImage(image))
            {
                //录像
                SolidBrush drawBrush = new SolidBrush(Color.Yellow);

                Font drawFont = new Font(“Arial“ 6 Fontstyle.Bold GraphicsUnit.Millimeter);
                int xPos = image.Width - (image.Width - 15);
                int yPos = 10;
                //写到屏幕上的时间
                drawDate = DateTime.Now.ToString(“yyyy-MM-dd HH:mm:ss“);

                g.DrawString(drawDate drawFont drawBrush xPos yPos);
                if (!Directory.Exists(videoPath))
                    Directory.CreateDirectory(videoPath);

                //创建文件

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      44544  2013-07-15 23:04  OCVideoApplicationLibAForge.Controls.dll

     文件      17920  2013-07-15 23:04  OCVideoApplicationLibAForge.dll

     文件     262656  2013-07-15 23:04  OCVideoApplicationLibAForge.Imaging.dll

     文件      68096  2013-07-15 23:04  OCVideoApplicationLibAForge.Math.dll

     文件      61440  2013-07-15 23:04  OCVideoApplicationLibAForge.Video.DirectShow.dll

     文件      20992  2013-07-15 23:04  OCVideoApplicationLibAForge.Video.dll

     文件      61952  2013-07-15 23:07  OCVideoApplicationLibAForge.Video.FFMPEG.dll

     文件     241743  2013-07-15 23:07  OCVideoApplicationLibAForge.Video.FFMPEG.xml

     文件   13698048  2013-01-29 15:58  OCVideoApplicationLibavcodec-53.dll

     文件     350208  2013-01-29 15:58  OCVideoApplicationLibavdevice-53.dll

     文件     924672  2013-01-29 15:58  OCVideoApplicationLibavfilter-2.dll

     文件    2523136  2013-01-29 15:58  OCVideoApplicationLibavformat-53.dll

     文件     139776  2013-01-29 15:58  OCVideoApplicationLibavutil-51.dll

     文件     161280  2013-01-29 15:58  OCVideoApplicationLibpostproc-52.dll

     文件      35840  2013-01-29 15:58  OCVideoApplicationLibswresample-0.dll

     文件     302592  2013-01-29 15:58  OCVideoApplicationLibswscale-2.dll

     文件        260  2016-06-12 15:34  OCVideoApplicationOCVideoApplicationapp.config

     文件      44544  2013-07-15 23:04  OCVideoApplicationOCVideoApplicationinDebugAForge.Controls.dll

     文件      66108  2013-07-15 23:04  OCVideoApplicationOCVideoApplicationinDebugAForge.Controls.xml

     文件      17920  2013-07-15 23:04  OCVideoApplicationOCVideoApplicationinDebugAForge.dll

     文件     262656  2013-07-15 23:04  OCVideoApplicationOCVideoApplicationinDebugAForge.Imaging.dll

     文件      68096  2013-07-15 23:04  OCVideoApplicationOCVideoApplicationinDebugAForge.Math.dll

     文件      61440  2013-07-15 23:04  OCVideoApplicationOCVideoApplicationinDebugAForge.Video.DirectShow.dll

     文件      20992  2013-07-15 23:04  OCVideoApplicationOCVideoApplicationinDebugAForge.Video.dll

     文件      61952  2013-07-15 23:07  OCVideoApplicationOCVideoApplicationinDebugAForge.Video.FFMPEG.dll

     文件     241743  2013-07-15 23:07  OCVideoApplicationOCVideoApplicationinDebugAForge.Video.FFMPEG.xml

     文件   13698048  2013-01-29 15:58  OCVideoApplicationOCVideoApplicationinDebugavcodec-53.dll

     文件     350208  2013-01-29 15:58  OCVideoApplicationOCVideoApplicationinDebugavdevice-53.dll

     文件     924672  2013-01-29 15:58  OCVideoApplicationOCVideoApplicationinDebugavfilter-2.dll

     文件    2523136  2013-01-29 15:58  OCVideoApplicationOCVideoApplicationinDebugavformat-53.dll

............此处省略46个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)