Capture/ Record The Desktop To Video File

Small command line using ffmpeg.exe to capture/recorde the desktop into a video file. In a command prompt window just type,

ffmpeg -f gdigrab -framerate 24 -i desktop -preset ultrafast -pix_fmt yuv420p out.mp4

Simple as that. The directory where the ffmpeg.exe is sitting this is where the mp4 video file will be created. This was a sample using it with the ffmpeg.exe in a command prompt window.
 
This is how to use it in c# in this case in visual studio 2013 express. 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. using System.IO;  
  7. using System.Diagnostics;  
  8.   
  9. namespace Ffmpeg_App  
  10. {  
  11.     class Ffmpeg  
  12.     {  
  13.         Process process;  
  14.   
  15.         public void Start(string FileName, int Framerate)  
  16.         {  
  17.             process = new System.Diagnostics.Process();  
  18.             process.StartInfo.FileName = @"D:\ffmpegx86\ffmpeg.exe"// Change the directory where ffmpeg.exe is.  
  19.             process.EnableRaisingEvents = false;  
  20.             process.StartInfo.WorkingDirectory = @"D:\ffmpegx86"// The output directory  
  21.             process.StartInfo.Arguments = @"-f gdigrab -framerate " + Framerate + " -i desktop -preset ultrafast -                                                                     pix_fmt yuv420p " + FileName;  
  22.             process.Start();  
  23.             process.StartInfo.UseShellExecute = false;  
  24.             process.StartInfo.CreateNoWindow = false;  
  25.             Close();  
  26.         }  
  27.   
  28.         public void Close()  
  29.         {  
  30.             process.Close();  
  31.         }  
  32.     }  
  33. }  
And this is how to use it in Form1,
 
In top of form1,
  1. Ffmpeg fpeg = new Ffmpeg();   
Button click event to start, 
  1. private void Start_Click(object sender, EventArgs e)  
  2.         {  
  3.             fpeg.Start("test.mp4", 24);  
  4.         }  
Button click event to stop, 
  1. private void Stop_Click(object sender, EventArgs e)  
  2.         {  
  3.             fpeg.Close();  
  4.         }  
Example of two video i recorded,
 
https://www.youtube.com/watch?v=6Zw_fkMJ-qY&feature=youtu.be
 
And
 
https://www.youtube.com/watch?v=yJY-sOjrIx8