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.
Install
wmctrlif it is not already installed:- Debian/Ubuntu/Mint:
sudo apt install wmctrl - Fedora/RHEL:
sudo dnf install wmctrl - Arch Linux:
sudo pacman -S wmctrl
- Debian/Ubuntu/Mint:
Run the following command to list all active windows:
wmctrl -lThe output will look similar to this:
0x03c00003 0 hostname Terminal 0x0420000a 0 hostname Mozilla Firefox 0x04e00002 0 hostname VLC media playerThe 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.
Run the command in your terminal:
xwininfoYour cursor will turn into a crosshair. Click on the window you want to record.
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.mp4Key Parameters:
-f x11grab: Instructs FFmpeg to use the X11 screen-grabbing input device.-window_id 0x4e00002: Tells FFmpeg to restrict the capture to the window with this specific ID.-framerate 30: Sets the video capture rate to 30 frames per second.-i :0.0: Specifies the target X11 display (usually:0.0or:0).