Record Linux Screen with FFmpeg x11grab

This article explains how to capture your Linux desktop screen using the FFmpeg x11grab input device. You will learn the basic command syntax, how to define screen resolutions and frame rates, how to capture specific offsets or sub-regions of your display, and how to record synchronized audio alongside your video capture.

Prerequisites

To use x11grab, your Linux system must be running the X11 (Xorg) display server. Note that x11grab does not natively support Wayland; if you are on a Wayland-based system, you must run your session under XWayland or use alternative tools like PipeWire. You also need FFmpeg installed with x11grab support enabled (which is standard in most package manager distributions).

Basic Screen Recording Command

The simplest way to record your entire screen is to specify the input format as x11grab, set the video size to match your monitor’s resolution, and target your X display (usually :0.0).

ffmpeg -f x11grab -video_size 1920x1080 -i :0.0 output.mp4

Adjusting the Frame Rate

By default, FFmpeg captures at a low frame rate. To get smooth video playback, use the -framerate option before the input.

ffmpeg -f x11grab -framerate 30 -video_size 1920x1080 -i :0.0 output.mp4

Setting -framerate 30 or -framerate 60 is ideal for standard video captures and gaming records.

Capturing a Specific Screen Region

If you want to record only a portion of your screen rather than the whole display, you can specify x and y coordinate offsets in the -i parameter. The syntax is :display_number.screen_number+x_offset,y_offset.

To capture a 1024x768 area starting 100 pixels from the left and 200 pixels from the top of the screen:

ffmpeg -f x11grab -video_size 1024x768 -i :0.0+100,200 output.mp4

Recording Screen with Audio

To record desktop audio or microphone input alongside the video, you must combine the x11grab input with an audio grabber like PulseAudio (pulse) or ALSA (alsa).

The following command records the screen and grabs the default PulseAudio input (such as your microphone):

ffmpeg -f x11grab -video_size 1920x1080 -i :0.0 -f pulse -i default output.mp4

To capture internal desktop audio instead of your microphone, you may need to use tools like pavucontrol (PulseAudio Volume Control) to route your system’s “Monitor of [Output Device]” to the default recording channel while FFmpeg is running.