Capture Specific Monitor with FFmpeg gdigrab

Capturing a specific monitor on Windows using FFmpeg's gdigrab device requires targeting the virtual desktop using coordinate offsets and screen dimensions rather than selecting a monitor index. Because gdigrab treats all connected displays as a single unified desktop canvas, you must define the exact resolution and the horizontal and vertical starting positions of the display you wish to record.

Understanding Virtual Screen Coordinates

Windows positions multiple monitors along a continuous X and Y coordinate plane. The primary monitor typically starts at coordinate (0,0). Additional monitors extend outward from this origin depending on how they are arranged in your Windows Display Settings:

  • A monitor to the right of a 1920x1080 primary display starts at X=1920, Y=0.
  • A monitor to the left of the primary display starts at negative coordinates, such as X=-1920, Y=0.
  • A monitor above or below starts at negative or positive Y offsets, respectively.

You can verify your monitor resolutions and layout by navigating to Settings > System > Display in Windows.

The Basic Command Structure

To record a specific display, combine the -video_size, -offset_x, and -offset_y flags before the input declaration -i desktop:

ffmpeg -f gdigrab -framerate 30 -offset_x [X_OFFSET] -offset_y [Y_OFFSET] -video_size [WIDTHxHEIGHT] -i desktop output.mp4

Examples

Capturing the Primary Monitor (1080p)

If your primary monitor is standard Full HD (1920x1080) located at the origin:

ffmpeg -f gdigrab -framerate 60 -offset_x 0 -offset_y 0 -video_size 1920x1080 -i desktop -c:v libx264 -preset ultrafast primary_output.mp4

Capturing a Secondary Monitor to the Right

If your second monitor is a 1920x1080 screen positioned directly to the right of a 1920x1080 primary screen:

ffmpeg -f gdigrab -framerate 60 -offset_x 1920 -offset_y 0 -video_size 1920x1080 -i desktop -c:v libx264 -preset ultrafast secondary_output.mp4

Capturing a Secondary Monitor to the Left

If your second monitor is positioned to the left of the primary screen:

ffmpeg -f gdigrab -framerate 60 -offset_x -1920 -offset_y 0 -video_size 1920x1080 -i desktop -c:v libx264 -preset ultrafast left_screen_output.mp4

Additional Configuration Options

  • Hide or Show the Mouse Cursor: Control mouse visibility using the -draw_mouse flag. Set -draw_mouse 0 to hide it, or -draw_mouse 1 to include it in the recording.
  • Pixel Format: Many video players require YUV 4:2:0 color. Add -pix_fmt yuv420p to your output parameters to ensure wide playback compatibility.