How to Use FFmpeg ddagrab for Windows Screen Capture

Capturing your Windows desktop with high performance requires leveraging hardware acceleration. This article provides a straightforward guide on how to use FFmpeg’s ddagrab (Desktop Duplication API) filter to record your screen efficiently on Windows. You will learn the basic command syntax, hardware encoding options, and advanced configuration settings to achieve low-latency, high-frame-rate desktop captures without overloading your CPU.

What is ddagrab?

The ddagrab filter utilizes the Microsoft Desktop Duplication API (DXGI), which allows FFmpeg to capture desktop frames directly from the graphics card. Because the frames remain on the GPU, this method is significantly faster and uses far fewer CPU resources than older methods like gdigrab.

Prerequisites

To use ddagrab, you must meet the following requirements: * Windows 8 or newer. * A dedicated or integrated GPU that supports DirectX 11. * FFmpeg installed and added to your system’s PATH.

Basic Capturing Command

To perform a basic screen capture using ddagrab and encode it using your CPU, use the following command:

ffmpeg -f lavfi -i ddagrab=framerate=60 -c:v libx264 -pix_fmt yuv420p output.mp4

Fully Hardware-Accelerated Capture (Zero-Copy)

To get the best performance, you should keep the captured video frames on the GPU memory and pass them directly to a hardware encoder. This is called “zero-copy” capture.

If you have an NVIDIA graphics card, use the following command to capture and encode using NVENC:

ffmpeg -init_hw_device d3d11va -filter_complex ddagrab=framerate=60,hwupload=extra_hw_frames=3[out] -map [out] -c:v h264_nvenc -delay 0 output.mp4

For Intel Quick Sync (QSV) users, the encoding codec can be changed to -c:v h264_qsv, and for AMD users, -c:v h264_amf.

Useful ddagrab Configuration Parameters

You can customize the ddagrab input filter by appending options separated by colons: