This can be done with the next command:
$ ffmpeg -r 50 -s 1280x720 -f x11grab -i :0.0 -vcodec msmpeg4v2 -qscale 1 output_filename.avi
Explanation of this command is shown below.
$ ffmpeg -r 50
The frame rate in which you want to record, in this example 50 frames per seconds is used.
The screen resolution that you want to record.
Do not try to use a larger screen size than your desktop screen size.
This flag is used to tell ffmpeg to record the x11 window.
Here the special input file is an x11 screen buffer.
In this case, we record the default window 0.
You can also record another active x11 server window like -i :1.0.
If x11 server window is active the screen will be black.
We prefer to use one of the encoder msmpeg4v2 ( Microsoft MPEG4-v2 codec).
This sets the quality of the file to highest (in this case is 1).
The file name for the output file.