List Linux Window IDs for FFmpeg x11grab

To record a specific window on Linux using FFmpeg’s x11grab input device, you must target the window’s unique X11 window ID. This guide explains how to quickly find active window IDs using command-line utilities like wmctrl and xwininfo, and how to pass those IDs into your FFmpeg command.

Method 1: List All Windows Using wmctrl

The easiest way to see a complete list of all active windows and their corresponding IDs is by using the wmctrl tool.

  1. Install wmctrl if it is not already installed:

    • Debian/Ubuntu/Mint: sudo apt install wmctrl
    • Fedora/RHEL: sudo dnf install wmctrl
    • Arch Linux: sudo pacman -S wmctrl
  2. Run the following command to list all active windows:

    wmctrl -l
  3. The output will look similar to this:

    0x03c00003  0 hostname Terminal
    0x0420000a  0 hostname Mozilla Firefox
    0x04e00002  0 hostname VLC media player

    The first column contains the hexadecimal window ID (e.g., 0x0420000a), which you will use for FFmpeg.

Method 2: Identify a Window Interactively Using xwininfo

If you have many open windows and want to identify a specific one visually, use xwininfo.

  1. Run the command in your terminal:

    xwininfo
  2. Your cursor will turn into a crosshair. Click on the window you want to record.

  3. The terminal will output detailed information about the selected window. Look for the line containing the Window ID:

    xwininfo: Window id: 0x4e00002 "VLC media player"

    Copy the hex code (e.g., 0x4e00002).

Recording the Window with FFmpeg

Once you have the hexadecimal window ID, you can feed it directly to FFmpeg using the -window_id flag.

Replace 0x4e00002 with your target window ID in the command below:

ffmpeg -f x11grab -window_id 0x4e00002 -framerate 30 -i :0.0 output.mp4

Key Parameters: