How to record screen with FFmpeg?

I want to record my screen and make a video out of it, is there any way I can do it using 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

To capture screen films in Windows 10, I’m using Ffmpeg:

Ffmpeg with the following settings: -rtbufsize 1500M -f gdigrab -framerate 29.97 -draw mouse 0 -offset x 2777 -offset y 344 -video size 1280x720 -i desktop -c:v libx264 -vf format=yuv420p -preset ultrafast D:/myvideo.mpg

The recorded files playback without any issues in VLC. This issue message appears when I play them back in the default Windows Media Player or “Movies & TV” ERROR INVALID MODULETYPE 0xc10100be

Do I have to add any settings to Ffmpeg to use it on Windows?

Try this:

Replace .mpg with .mp4.

Thanks, Uma!

I recently made the changes as you suggest but nothing happened, still getting the same error.

Any other idea?

Did you truly rerun the command with the correct output name (myvideo.mp4), or you just alter the name of the existing file?

Thank you!

I had forgotten that “mpg” files are not the same as “mp4” as a container. Nicely rounded up.

Setting the output file format to “.mp4” was therefore part one. Although the Windows players were still showing black video, this at least halted the crashes and problems. Setting the pixel size to yuv420p was part two.

Here is a working FFmpeg command, though I’m sure it may be improved:

ffmpeg -rtbufsize 1500M -f gdigrab -framerate 29.97 -draw_mouse 0 -offset_x 2633 -offset_y 103 -video_size 1280x720 -i desktop -pix_fmt yuv420p -c:v libx264 -preset ultrafast D:/myvideo.mp4