17

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?

painotpi
  • 6,894
  • 1
  • 37
  • 70
masterchris_99
  • 2,683
  • 7
  • 34
  • 55

2 Answers2

10

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) { }
        }
Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431
masterchris_99
  • 2,683
  • 7
  • 34
  • 55
  • 2
    Old post but I feel I should mention that using Expression Encoder requires a pro license if you wish to record video with a duration over 10 minutes, and GPU encoding also requires pro license. (Personally I can't get any output without GPU encoding) – Sakuya Oct 08 '15 at 10:20
  • Thank you for the answer @masterchris_99 . I would like to use also MEE, but get the error below; An exception of type 'System.IO.FileNotFoundException' occurred in PCba.Tests.Repository.dll but was not handled in user code Additional information: Could not load file or assembly 'Microsoft.Expression.Encoder, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. – cell-in Jun 17 '16 at 05:53
3

Edit Based on Comment Feedback:

A developer by the name baSSiLL has graciously shared a repository that has a screen recording c# library as well as a sample project in c# that shows how it can be used to capture the screen and mic.

Starting a screen capture using the sample code is as straight forward as:

recorder = new Recorder(_filePath,
            KnownFourCCs.Codecs.X264, quality,
            0, SupportedWaveFormat.WAVE_FORMAT_44S16, true, 160);

_filePath is the path of the file I'd like to save the video to.

You can pass in a variety of codecs including AVI, MotionJPEG, X264, etc. In the case of x264 I had to install the codec on my machine first but AVI works out of the box.

Quality only comes into play when using AVI or MotionJPEG. The x264 codec manages its own quality settings.

The 0 above is the audio device I'd like to use. The Default is zero.

It currently supports 2 wave formats. 44100 at 16bit either stereo or mono.

The true parameter indicates that I want the audio encoded into mp3 format. I believe this is required when choosing x264 as the uncompressed audio combined in a .mp4 file would not play back for me.

The 160 is the bitrate at which to encode the audio.

~~~~~

To stop the recording you just

recorder.Dispose(); recorder = null;

Everything is open source so you can edit the recorder class and change dimensions, frames per second, etc.

~~~~

To get up and running with this library you will need to either download or pull from the github / codeplex libraries below. You can also use NuGet:

Install-Package SharpAvi

Original Post:

Sharp AVI: https://sharpavi.codeplex.com/ or https://github.com/baSSiLL/SharpAvi

There is a sample project within that library that has a great screen recorder in it along with a menu for settings/etc.

I found Screna first from another answer on this StackoverFlow question but I ran into a couple issues involving getting Mp3 Lame encoder to work correctly. Screna is a wrapper for SharpAVI. I found by removing Screna and going off of SharpAvi's sample I had better luck.

ickydime
  • 1,051
  • 10
  • 22
  • Its been awhile but I believe SharpAVI has a version of LameEncoder that I just could not recreate. I forget the exact issue but think whenever I built LameEncoder it was missing some function or it was a different method name, etc. I found the actual DLL files within SharpAVI and once I used that It went smoothly. – ickydime Apr 04 '16 at 17:59
  • When I tried to use the Lame dll files with Screna there was a miss match in methods. Its as if Screna was using a different version of lame. And I couldn't recreate the lame dll that was needed. – ickydime Apr 15 '16 at 16:43