Created
August 28, 2014 13:35
-
-
Save shvyrev/844fe7f7afd12b457e8b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Diagnostics; | |
using System.Drawing; | |
using System.Linq; | |
using System.Text; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using System.Windows.Forms; | |
using AForge.Video; | |
using AForge.Video.FFMPEG; | |
namespace WindowsFormsApplication1 | |
{ | |
public partial class Form1 : Form | |
{ | |
private VideoFileWriter writer; | |
private int width = SystemInformation.VirtualScreen.Width; | |
private int height = SystemInformation.VirtualScreen.Height; | |
private ScreenCaptureStream streamVideo; | |
private Stopwatch stopWatch = new Stopwatch(); | |
public Form1() | |
{ | |
InitializeComponent(); | |
writer = new VideoFileWriter(); | |
} | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
try | |
{ | |
Start(); | |
} | |
catch (Exception) | |
{ | |
throw; | |
} | |
} | |
private void Start() | |
{ | |
recorded = true; | |
frameCount = 0; | |
try | |
{ | |
writer.Open("C:\\test1222.avi", width, height, 12, VideoCodec.MPEG4, 5000); | |
Rectangle screenArea= Rectangle.Empty; | |
foreach (var screen in System.Windows.Forms.Screen.AllScreens) | |
{ | |
screenArea = Rectangle.Union(screenArea, screen.Bounds); | |
} | |
streamVideo = new ScreenCaptureStream(screenArea); | |
streamVideo.NewFrame += new NewFrameEventHandler(handler_videoNewFrame); | |
streamVideo.Start(); | |
stopWatch.Start(); | |
} | |
catch (Exception) | |
{ | |
throw; | |
} | |
} | |
public bool recorded { get; set; } | |
private void handler_videoNewFrame(object sender, NewFrameEventArgs eventargs) | |
{ | |
if (recorded) | |
{ | |
frameCount++; | |
writer.WriteVideoFrame(eventargs.Frame); | |
} | |
else | |
{ | |
stopWatch.Restart(); | |
Thread.Sleep(500); | |
streamVideo.SignalToStop(); | |
Thread. Sleep(500); | |
writer.Close(); | |
} | |
} | |
public int frameCount { get; set; } | |
private void button2_Click(object sender, EventArgs e) | |
{ | |
recorded = false; | |
} | |
} | |
} |
donotfeedaslender
commented
Jul 18, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment