Need to record your screen on a Linux desktop but you aren’t satisfied with the screen recorders that are available? Consider using the powerful FFMPEG encoding tool. It’s very versatile and can do multiple things, including screen capture on the Linux desktop.
The setup for FFMPEG is a little more complex than hitting a “record” button in a program, but the tradeoff is that it offers up some real power, automation, and customization that other GUI recording tools on Linux don’t offer.
sudo apt install ffmpeg
sudo apt-get install ffmpeg
sudo pacman -S ffmpeg
sudo dnf install ffmpeg
sudo zypper install ffmpeg
The FFMPEG encoding utility is one of the most used video tools on Linux and operating systems in general. It is because of this, the tool is supported on nearly every Linux distribution out there. If for some reason, the Linux operating system you use doesn’t support FFMPEG with a binary package, the best course of action is to install the software manually, from the FFMPEG Github repository.
To do this, first, make sure you have the git tool installed. Once installed, open up a terminal and do the following to build the software:
git clone https://github.com/FFmpeg/FFmpeg.git
Enter the FFMPEG directory with the CD command.
Before you begin compiling the software, you’ll need to create a new configuration file. This is so that the software knows your system and can build correctly.
Having issues with ./configure? Try:
The next step in the compiling process is to use the make command. Make does the majority of the building, and its the most critical step in installing FFMPEG.
Lastly, install the software on the system with the install command.
sudo make install
Record Your Screen
The FFMPEG software is very versatile and can be configured to do just about anything, including video capture. That said, the default type of visual capture that is possible works by capturing every screen available. It’s crude, but it works. To use it, open up a terminal window. Inside the terminal, before starting capture, it’s a good idea to make a special folder to work in. This way all recordings go there, rather than in random places.
Using the mkdir command to create a new capture folder inside of ~/Videos.
mkdir -p ~/Videos/ffmpeg-capture/
Then, move the terminal into the new directory, so that the capture will take place there, rather than another location.
You can now start recording your screen. Here is the basic capture command:
ffmpeg -f x11grab -y -r 30 -s 1920x1080 -i :0.0 -vcodec huffyuv out.avi
Be sure to change the resolution in the command to correspond with the monitor you are recording on. In the command shown above, the resolution is set to 1920×1080 and it is set to record the desktop at 30 frames per second, and output it to a file named capture.mp4. For the most part, screen-casting at 25 FPS is fine. However, if you’re looking to record something that requires a high frame rate (like video games, or moving images), consider changing the 30 to 60. Keep in mind that changing the FPS from 30 to 60 will result in slower performance on weaker computers. Before doing this, try and find out if your Linux computer can handle the up in performance beforehand.
Quit the recording at any time by tapping the ‘q’ key on the keyboard.
Record Screen And Webcam
It is possible to capture the desktop in FFMPEG and record from your webcam at the same time. To do so, you’ll need to use two separate commands. The first command to use will display the active webcam currently connected to Linux. The second command is the screen capture.
For the first command, open a terminal window and enter the following:
ffplay -f video4linux2 -i /dev/video0 -video_size 320x240 -fflags nobuffer
This setup will display a webcam window with almost no latency directly on the screen with a 320×240 screen resolution. Don’t worry about the size, as it’ll look just fine on the recording. Feel free to grab the cam window and put it in any place you’d like. Additionally, if your window manager supports hiding, consider making the camera window controls disappear for a better effect.
Note: if you dislike the 320×240 resolution, consider changing it to something else. Look into the webcam’s manual to find the perfect resolution to use, but remember, don’t use a higher resolution than the device can handle or things will break.
While the first terminal is open, your webcam will be displayed on the desktop. Next, open a second terminal window to start the actual recording:
ffmpeg -f x11grab -r 30 -s cif -i :0.0 capture.mp4
As long as these two terminal windows are open, you’ll be recording the desktop at 30 FPS, and displaying a webcam.
To stop the recording, go to the FFMPEG window and press “q” to quit, then move on to the FFPLAY terminal (the one broadcasting the cam) and press Ctrl + Z.
Finished recordings are saved in ~/Videos/ffmpeg-capture/