使用AForge錄製視頻,基於Winform開發git
須要先導入github
using AForge.Video;
using AForge.Video.FFMPEG;ide
兩個工具包工具
//初始化設置AForge所需的參數
this.screenWidth = SystemInformation.VirtualScreen.Width;
this.screenHight = SystemInformation.VirtualScreen.Height;
this.frameRate = DEFAULT_FRAME_RATE;
this.isRecording = false;
this.framesCount = default(int);
this.screenArea = Rectangle.Empty;
this.videoWriter = new VideoFileWriter();
this.folderBrowser = new FolderBrowserDialog();
this.videoCodec = (VideoCodec)3;
this.bitRate = 3000000;this
//寫入當前電腦上的全部屏幕(可能會有雙屏或多屏)
foreach (Screen screen in Screen.AllScreens)
{
this.screenArea = Rectangle.Union(this.screenArea, screen.Bounds);
}
//打開寫入流
this.videoWriter.Open
(this.fileName, this.screenWidth, this.screenHight,
this.frameRate, this.videoCodec, this.bitRate);orm
//初始化設置參數
InitializeRecordingParameters(AppDomain.CurrentDomain.BaseDirectory + "aaa.avi");
//開始錄製
this.videoStreamer = new ScreenCaptureStream(this.screenArea);
//設置每幀圖像錄製的回調
this.videoStreamer.NewFrame += new NewFrameEventHandler((object senders, NewFrameEventArgs es) =>
{
this.framesCount++;
//寫入到視頻
this.videoWriter.WriteVideoFrame(es.Frame);
});
this.videoStreamer.Start();視頻
//中止錄像
videoStreamer.Stop();
//關閉寫入器
videoWriter.Close();開發
支持錄製聲音和暫停以及錄製攝像頭,須要的話能夠加羣討論get
完整Demo能夠去Github上下載:it
https://github.com/a935368322/Kogel.Record.Test
若有問題也能夠加QQ羣討論:
技術羣 710217654