Record your desktop from the terminal with FFmpeg

Record screen with terminal and FFmpegA 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:

  1. 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:ffmpeg in terminal
  2. 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
  1. 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".
  1. 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?

The content of the article adheres to our principles of editorial ethics. To report an error click here.

7 comments, leave yours

Leave a Comment

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



  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Creole Software said

    New blog about Free Software from Argentina!

    Visit us:

    On Facebook: SoftwareCriollo Argentina

    On twitter: @softwarecriollo

    We must spread the knowledge to be free!


  2.   Gaspar Fernandez said

    It's nice to have this line on hand. The other day I was fighting to make a screencast with ffmpeg and I had the problem of the audio, which did not synchronize well.

    I solved it in a very rudimentary way ... recording the audio with arecord separately and then joining the streams: S: S

  3.   mom 21 mom said

    yes very useful friends.
    I was inspired by bash and put together a script named "xrec" and packaged it in deb.

    If you want to try it, you are invited

  4.   SergioJP said

    I use the following command:
    $ ffmpeg -f oss -i / dev / dsp1 -f x11grab -s sxga -r 24 -i: 0.0 /home/seunome/Videos/teste.mpg

    Or "-f oss" is that states that want to record audio as well,
    "-I / dev / dsp" tells the audio input device what to use.
    Use “-i / dev / dsp0” or “-i / dev / dsp1” (For me, it worked with DSP1)
    The "-f x11grab" reports that you want to record the Grafix X11 server video screen.
    Or "-s sxga" equals "-s 1280 × 1024" which is the resolution of my display (LCD). Another option is xga which corresponds to 1024 × 768, To know more read the documentation of ffmpeg.
    Or "-r 24" reports that we want to record 24 frames (images) per second, which is the minimum to have the feel of a movie.
    The "-i: 0.0" indicates that we want to capture the display screens em "0.0" of the X11.
    Finally just configure the directory and end filename to be generated.
    That's it, you can read the ffmpeg documentation to improve and get better quality.
    Thank you all.

  5.   tarribalis said

    Thanks. In the resolution, eg 1024X600, the X must be capitalized for the command to work.

  6.   Santiago Yornet said

    How about, I tried all the commands you said and they all record me video without audio. I have Ubuntu 20.04. Any suggestions?

    1.    Diego said

      Ubuntu changed base drivers like Debian and others, I don't know which one they will use now since I still live in the past.
      Find out which ones use and replace the ones from Alsa or Pulse.