资源简介
最最简单的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:\OCVideo\Video\“; //视频文件路径
private string imagePath = @“D:\OCVideo\Images\“; //图像文件路径
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 OCVideoApplication\Lib\AForge.Controls.dll
文件 17920 2013-07-15 23:04 OCVideoApplication\Lib\AForge.dll
文件 262656 2013-07-15 23:04 OCVideoApplication\Lib\AForge.Imaging.dll
文件 68096 2013-07-15 23:04 OCVideoApplication\Lib\AForge.Math.dll
文件 61440 2013-07-15 23:04 OCVideoApplication\Lib\AForge.Video.DirectShow.dll
文件 20992 2013-07-15 23:04 OCVideoApplication\Lib\AForge.Video.dll
文件 61952 2013-07-15 23:07 OCVideoApplication\Lib\AForge.Video.FFMPEG.dll
文件 241743 2013-07-15 23:07 OCVideoApplication\Lib\AForge.Video.FFMPEG.xm
文件 13698048 2013-01-29 15:58 OCVideoApplication\Lib\avcodec-53.dll
文件 350208 2013-01-29 15:58 OCVideoApplication\Lib\avdevice-53.dll
文件 924672 2013-01-29 15:58 OCVideoApplication\Lib\avfilter-2.dll
文件 2523136 2013-01-29 15:58 OCVideoApplication\Lib\avformat-53.dll
文件 139776 2013-01-29 15:58 OCVideoApplication\Lib\avutil-51.dll
文件 161280 2013-01-29 15:58 OCVideoApplication\Lib\postproc-52.dll
文件 35840 2013-01-29 15:58 OCVideoApplication\Lib\swresample-0.dll
文件 302592 2013-01-29 15:58 OCVideoApplication\Lib\swscale-2.dll
文件 260 2016-06-12 15:34 OCVideoApplication\OCVideoApplication\app.config
文件 44544 2013-07-15 23:04 OCVideoApplication\OCVideoApplication\bin\Debug\AForge.Controls.dll
文件 66108 2013-07-15 23:04 OCVideoApplication\OCVideoApplication\bin\Debug\AForge.Controls.xm
文件 17920 2013-07-15 23:04 OCVideoApplication\OCVideoApplication\bin\Debug\AForge.dll
文件 262656 2013-07-15 23:04 OCVideoApplication\OCVideoApplication\bin\Debug\AForge.Imaging.dll
文件 68096 2013-07-15 23:04 OCVideoApplication\OCVideoApplication\bin\Debug\AForge.Math.dll
文件 61440 2013-07-15 23:04 OCVideoApplication\OCVideoApplication\bin\Debug\AForge.Video.DirectShow.dll
文件 20992 2013-07-15 23:04 OCVideoApplication\OCVideoApplication\bin\Debug\AForge.Video.dll
文件 61952 2013-07-15 23:07 OCVideoApplication\OCVideoApplication\bin\Debug\AForge.Video.FFMPEG.dll
文件 241743 2013-07-15 23:07 OCVideoApplication\OCVideoApplication\bin\Debug\AForge.Video.FFMPEG.xm
文件 13698048 2013-01-29 15:58 OCVideoApplication\OCVideoApplication\bin\Debug\avcodec-53.dll
文件 350208 2013-01-29 15:58 OCVideoApplication\OCVideoApplication\bin\Debug\avdevice-53.dll
文件 924672 2013-01-29 15:58 OCVideoApplication\OCVideoApplication\bin\Debug\avfilter-2.dll
文件 2523136 2013-01-29 15:58 OCVideoApplication\OCVideoApplication\bin\Debug\avformat-53.dll
............此处省略46个文件信息
评论
共有 条评论