Search code examples
c#screen-capturedesktop-recording

How to capture screen to be video using C# .Net?


I know there are lots of question like this.

But I don't want to use the Windows media encoder 9 because it's a problem to get one, and then it is no longer supported.

I know that, one possibility is to capture lots of screenshots and create a video with ffmpeg but I don't want use third party executables.

Is there are a .net only solution?


Solution

  • the answer is the Microsoft Expression Encoder. It is according to my opinion the easiest way to record something on vista and windows 7

    private void CaptureMoni()
            {
    
                try
                {
                    Rectangle _screenRectangle = Screen.PrimaryScreen.Bounds;
                    _screenCaptureJob = new ScreenCaptureJob();
                    _screenCaptureJob.CaptureRectangle = _screenRectangle;
                    _screenCaptureJob.ShowFlashingBoundary = true;
                    _screenCaptureJob.ScreenCaptureVideoProfile.FrameRate = 20;
                    _screenCaptureJob.CaptureMouseCursor = true;
    
                    _screenCaptureJob.OutputScreenCaptureFileName = string.Format(@"C:\test.wmv");
                    if (File.Exists(_screenCaptureJob.OutputScreenCaptureFileName))
                    {
                        File.Delete(_screenCaptureJob.OutputScreenCaptureFileName);
                    }
                    _screenCaptureJob.Start();
                }
                catch(Exception e) { }
            }