How To Record Linux Screen with Command Line

Currently, operating systems allow us to perform multiple actions on them regardless of the type of destination that is, administrative, personal or more.

Within these actions there is a special one that is very useful for its purpose, this action is to record the screen of our system which is helpful in cases:

Although it is true that there are various tools to do this today, we will show how to achieve it with a function integrated into the System, commands, this will be made with the FFmpeg Command Line.

What is FFmpeg? Is a framework recognized worldwide for its ability to decode, encode, transcode, transmit, filter and reproduce almost any multimedia.

Install FFmpeg on Linux


For this tutorial; we will use Ubuntu 17.10

1.Install FFmpeg in Ubuntu with:

sudo apt install ffmpeg

2. For other distros use the following commands:


sudo apt-get install ffmpeg


sudo dnf install ffmpeg

Arch Linux

sudo pacman -S ffmpeg


sudo zypper install ffmpeg

3. For other Linux distributions, execute the following sequence of commands:

git clone

cd FFmpeg



sudo make install


Record Screen with FFmpeg in Linux

1. Recommendation: keep the videos in a single folder, if you wish, create the following directory:

mkdir -p ~/Vídeos/ffmpeg-capture/
cd ~/Vídeos/ffmpeg-capture/

2. To Record your screen executes the following command:

fmpeg -vídeo_size 1600x795 -framerate 30 -f x1grab -i :0 -c:v libx264 -qp 0 -preset ultrafast TheLinuxCode.mp4

3. We cant see anything on the desktop but is recording. To stop the recording, we will use the q key.

Note: In some cases, we will see the following error:

Cannot open display :0.0, error 1.

:0.0: Input/output error

For its solution, we must execute the following command:


This will result in the screen number to use, 0 or 1, if it is number 1, it is enough to replace the zero on x1grab like this:

fmpeg -vídeo_size 1600x795 -framerate 30 -f x1grab -i :1 -c:v libx264 -qp 0 -preset ultrafast TheLinuxCode.mp4

4. If you want to look at the properties of the video, execute:

ffmpeg -i TheLinuxCode.mp4


Record Screen and Webcam with FFmpeg in Linux

We may want to capture the desktop in FFmpeg and record from our webcam at the same time. For that, we need to use two commands separately. The first command will display the active webcam connected to the Linux computer while the second command is the screen capture itself.


1. Execute this command:

ffplay -f vídeo4linux2 -i /dev/vídeo0 -vídeo_size 320x240 -fflags nobuffer

2. This line will display a window with the webcam practically without any latency at a screen resolution of 320×240. Now, we open another window of the terminal and execute the following:

ffmpeg -f x11grab -r 30 -s cif -i :0.0 TheLinuxCode.mp4
With these 2 terminal windows running, we will record the desktop at 30 FPS and display the webcam in real time.

3. To finish the process we will use Ctrl + Z keys


FFmpeg becomes a useful tool when it comes to recording our screen in Linux.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *