How to record screen with FFmpeg?

FFmpeg allows screen recording with all kinds of platforms and it is very easy to it. You can use the gdigrab input device on Windows or x11grab on Linux to record your screen with FFmpeg.
Here are some examples for Windows:

ffmpeg -f gdigrab -framerate 30 -i desktop -c:v libx264 -preset ultrafast -qp 0 output.mp4

  • -f gdigrab: Indicates that the Windows screen capture input format is gdigrab.
  • -framerate: is set to 30 frames per second with the -framerate 30 option. Adapt as necessary.
  • -i desktop: Takes a picture of the whole desk. If necessary, a specific screen or area can be specified.
  • -c:v libx264: Uses libx264 to set the video codec to H.264. Depending on your needs, a different codec may be selected.
  • -preset ultrafast: Select the speed-enhancing ultrafast encoding preset. Depending on how you would like to trade-off between compression and speed, you can change the preset.
  • -qp 0: For lossless quality, sets the quantization setting to 0. Adapt this to the quality you want.

There is a complete guide created by FFmpeg for screen recording. You can find all the details below.
https://trac.ffmpeg.org/wiki/Capture/Desktop