Set up Screen Recording Using ffmpeg on Ubuntu

As part of the Setup a Ubuntu Development Laptop with Me series, in this article, I worked with chatGPT but verified setp-by-step and successfully set up ffmpeg on my new laptop and able to record the screen and the audio

What is ffmpeg?

FFmpeg is a comprehensive, cross-platform software suite that allows for recording, converting, and streaming audio and video. It includes a vast collection of libraries and tools to process multimedia content, such as videos and audio tracks. Some of its core components and capabilities include:

  • ffmpeg: The command-line tool that enables users to convert multimedia files between formats, adjust video and audio settings, capture screen and audio, and perform many other tasks related to multimedia processing.
  • ffplay: A simple, portable media player using the FFmpeg libraries and the SDL library. It’s useful for quickly previewing files.
  • ffprobe: A command-line utility for gathering information from multimedia streams, such as sample rates for audio or frame rates for video, used primarily for analysis and debugging purposes.

Install ffmpeg by building from source

I decided to install from source because it will give me flexibility and my laptop is already set up to build a c/c++ applications

$ git clone ffmpeg
$ cd ffmpeg
$ ./configure --enable-gpl --enable-libx264
$ make -j$(nproc)
$ sudo make install

Verify that x11grab format has been enabled. You should see some text about x11grab

$ ffmpeg -formats | grep x11grab

Before recording, check the monitors via the xrandr command, and look for lines that are similar to the following:

$ xrandr | grep 'connected'
eDP-1 connected primary 1920x1200+0+1353 (normal left inverted right x axis y axis) 344mm x 215mm
HDMI-1-0 connected 3840x2160+1920+0 (normal left inverted right x axis y axis) 698mm x 393mm

The 1920x1200+0+1353 string indicates current resolution and position offset. To record, we will need th position offset 0+1353

The command I use to record on the smaller monitor is

ffmpeg -f x11grab -video_size 2560x1440 -i :0.0+1353,0 -f pulse -i default -c:v libx264 -preset ultrafast -crf 18 -c:a aac -b:a 192k output.mp4

Result – screen recording with audio

Here is the finished recording and you can see that i used chatPGT as my copilot to help me finish the setup end-to-end as well as my happy shouts of “Testing Testing Testing!”


No comments yet. Why don’t you start the discussion?

Leave a Reply