Capture Specific Window with FFmpeg gdigrab

Capturing a specific application window on Windows is highly efficient using FFmpeg's built-in gdigrab input device. This guide provides a straightforward, step-by-step tutorial on how to identify a target window's title and construct the precise FFmpeg command required to record only that specific window.

Step 1: Find the Exact Window Title

The gdigrab device identifies which window to capture by matching its exact title bar text. This title is case-sensitive and must be written exactly as it appears.

To find the exact title:

  1. Look at the top bar of the application window you want to capture.
  2. Alternatively, open Task Manager (Ctrl + Shift + Esc) to see the exact names of running applications.

For example, if you want to capture Notepad, the window title might be Untitled - Notepad.

Step 2: Run the FFmpeg Command

Once you have the window title, use the following command structure to start capturing:

ffmpeg -f gdigrab -framerate 30 -i title="Window Title" output.mp4

Replace "Window Title" with the exact name of your target window.

Example: Capturing Notepad

To record a window named Untitled - Notepad at 30 frames per second, run:

ffmpeg -f gdigrab -framerate 30 -i title="Untitled - Notepad" output.mp4

Step 3: Understanding the Parameters

  • -f gdigrab: Specifies the use of the GDI-based screen grabber device.
  • -framerate 30: Sets the capture frame rate to 30 FPS. You can increase this to 60 for smoother video.
  • -i title="Window Title": Instructs FFmpeg to capture the window matching this exact title. The title= prefix is mandatory.

Limitations and Troubleshooting

  • Minimized Windows: gdigrab cannot capture windows that are minimized. The target window must be open on your desktop, though it can be partially covered by other windows.
  • Black Screens: Some modern applications (like Google Chrome, Discord, or Spotify) use hardware acceleration, which can result in a blank or black window capture. If this occurs, disable "Hardware Acceleration" in the target application's settings.
  • Window Title Changes: If the application changes its title dynamically (for example, a web browser tab change), FFmpeg will lose the handle and stop capturing properly. Ensure the title remains static during recording.