Record Windows Screen with FFmpeg GDIGRAB

This article provides a quick and practical guide on how to record your Windows desktop screen using FFmpeg’s built-in gdigrab (Graphics Device Interface) device. You will learn how to capture your entire screen, record specific regions or windows, and optimize your command settings for smooth video output without relying on resource-heavy third-party software.

Prerequisites

To get started, ensure you have FFmpeg installed on your Windows system and added to your system’s PATH variable so you can run it directly from the Command Prompt or PowerShell.

Basic Command: Capture the Entire Desktop

To capture your entire Windows desktop at a standard frame rate of 30 frames per second (FPS), open your command line tool and run the following command:

ffmpeg -f gdigrab -framerate 30 -i desktop output.mkv

Parameter Breakdown: * -f gdigrab: Tells FFmpeg to use the Windows GDI screen grabber. * -framerate 30: Sets the capture rate to 30 frames per second. You can increase this to 60 for smoother motion. * -i desktop: Specifies the input source as your entire primary monitor. * output.mkv: The name and format of your output file.

To stop the recording at any time, press q or Ctrl + C in your command window.

Capture a Specific Screen Region

If you only want to record a specific portion of your screen rather than the entire desktop, you can specify the width, height, and offsets (coordinates starting from the top-left of your screen):

ffmpeg -f gdigrab -framerate 30 -video_size 1280x720 -offset_x 100 -offset_y 50 -i desktop output.mkv

Parameter Breakdown: * -video_size 1280x720: Defines the resolution of the recording area (width x height). * -offset_x 100: Moves the capture area 100 pixels to the right of the left edge of the screen. * -offset_y 50: Moves the capture area 50 pixels down from the top edge of the screen.

Capture a Specific Application Window

You can target a specific open window by using its exact title bar name as the input:

ffmpeg -f gdigrab -framerate 30 -i title="Calculator" output.mkv

Replace "Calculator" with the exact window title of the program you want to capture. Note that the target window must not be minimized during recording.

For a universally compatible MP4 output with efficient encoding, use the H.264 video codec along with a fast preset to prevent dropped frames:

ffmpeg -f gdigrab -framerate 30 -i desktop -c:v libx264 -preset ultrafast -pix_fmt yuv420p output.mp4

Parameter Breakdown: * -c:v libx264: Encodes the video stream to the widely compatible H.264 format. * -preset ultrafast: Instructs the CPU to compress the video as quickly as possible, reducing processing lag during real-time capture. * -pix_fmt yuv420p: Changes the pixel format to YUV 4:2:0, which is required for standard media players (like QuickTime and mobile devices) to play the MP4 file properly.