資源簡介
最最簡單的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個文件信息
評論
共有 條評論