Capture a Linux Window with FFmpeg and x11grab

Capturing a specific application window on Linux using FFmpeg and x11grab requires identifying the window’s precise geometry and screen coordinates. By utilizing the xwininfo utility, you can extract the target window’s dimensions and placement, then pass these parameters directly into an FFmpeg command to record only that specific application instead of your entire desktop. This guide will walk you through finding window coordinates and executing the exact FFmpeg command needed for a clean, isolated window capture.

Step 1: Find the Target Window Coordinates

Before running FFmpeg, you need to tell x11grab exactly where the window is positioned on your X11 display. The easiest way to find this is by using a utility called xwininfo.

  1. Open your terminal and run the following command:
xwininfo
  1. Your mouse cursor will turn into a crosshair. Click directly on the application window you want to record.
  2. The terminal will output several lines of data. Look for the following specific values:

For example, let’s assume xwininfo gave you a width of 1024, a height of 768, an absolute X of 100, and an absolute Y of 200.

Step 2: Construct and Run the FFmpeg Command

Once you have the coordinates, you can plug them into FFmpeg using the -video_size and -i (input) arguments. The standard syntax for desktop grabbing follows this structure:

ffmpeg -f x11grab -video_size [Width]x[Height] -i :0.0+[X-offset],[Y-offset] output.mp4

Using the example coordinates gathered from xwininfo, the complete command to capture just that specific application window looks like this:

ffmpeg -f x11grab -video_size 1024x768 -i :0.0+100,200 -c:v libx264 -preset ultrafast crf.mp4

Understanding the Command Flags

When you are finished recording, simply press q or Ctrl+C in the terminal to stop FFmpeg and save your video file.