A few hours ago we have published an article in which we explained how to convert an audio file to another format (also audio) with FFmpeg. In that article we also explain that the framework in question is a very powerful tool with which we can perform many tasks related to video and audio, and also that at another time we would teach you how to record the screen of our PC with FFmpeg from the terminal. That moment has come and the article will be this.
Record the screen with this framework it's going to be a bit more complicated than converting the audio. The difficulty is found at the time of writing the command, since what we have to remember is much more than putting a command, an "-i" and two files, the input and the output. In addition, the way to do it has been updated because they have modified the command / tool with which we will record the screen. Without further ado, we will now describe the steps to follow, which are none other than those found in the Official Site of the project.
FFmpeg allows us to record our desktop screen with and without audio
Like other programs such as VLC or SimpleScreenRecorder, FFmpeg allows us to record the screen of our desktop with and without audio. In addition, it will also allow us to record only a portion of our desktop, something that would be easier using an application with a user interface that would allow us to select the region to record with the pointer. In any case, the commands or steps to follow to record the screen of our desktop would be the following:
- As when converting files, we make sure that we have the necessary software installed. To do this, just type "ffmpeg" (without the quotes) in the terminal. We will see something like the following:
- If something like the above appears, we go to step 3. If it is not, we write the following in the terminal:
sudo apt install ffmpeg
- With the software installed, there would only be two more steps left: start the recording and stop it. To start it, we will write the following command.
ffmpeg -video_size 1920x1080 -framerate 25 -f x11grab -i :0.0 salida.mp4
- From the above it is necessary to take into account:
- 1920 × 1080 the size of the recording.
- framerate is the number of frames per minute.
- 0.0 is the region you will record. You can give a starting X and Y point to record a portion of the screen after the plus symbol, which might look like 0.0 + 100,200 for a window starting at point X = 100 and point Y = 200.
- output.mp4 is the output file. If we put it as in the previous command, the file will be saved in our personal folder with the name "output.mp4".
- Finally, to stop the recording we press Ctrl + C
Record screen with audio
If what we want is to also record the audio, the commands would look like this:
- To Pulse Audio:
ffmpeg -video_size 1920x1080 -framerate 25 -f x11grab -i :0.0 -f pulse -ac 2 -i default salida.mkv
- For ALSA:
ffmpeg -video_size 1920x1080 -framerate 25 -f x11grab -i :0.0 -f alsa -ac 2 -i hw:0 salida.mkv
To improve sound quality, it is best to close all unnecessary programs. In both cases, for stop recording press Ctrl + C. When we do this, the video will be waiting for us in our personal folder with the name that we have configured for it, in these cases "exit.mp4" or "exit.mkv".
Act quickly. take into account the size of the video. In the commands, I have put "1920 × 1080" because it is the size and resolution of my screen. The best thing is that each one adds the size / resolution of their own there. We must also bear in mind that it is not worth making a script to launch the order, since it could fail or, in the best of cases, we would complicate our lives at the moment in which we want to stop the recording. If you decide to test if it works well for you with a script, you can always try to stop the process with the "jobs" command, as we explained in this article last June.
What do you think of this method to record the screen from the terminal with FFmpeg?