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-f lavfi: Specifies that the input is a Libavfilter virtual device.-i ddagrab=framerate=60: Sets the input source toddagraband targets a capture rate of 60 frames per second.-c:v libx264: Encodes the video using the H.264 software encoder.-pix_fmt yuv420p: Converts the pixel format to ensure maximum compatibility with media players.
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-init_hw_device d3d11va: Initializes the Direct3D 11 hardware device.hwupload=extra_hw_frames=3: Uploads the captured DXGI textures directly to Direct3D 11 hardware frames, bypassing the system RAM.-c:v h264_nvenc: Uses NVIDIA’s hardware-accelerated H.264 encoder.
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:
Capture a specific monitor: By default,
ddagrabcaptures the primary monitor. To capture a secondary display, use theoutput_idxoption:ffmpeg -f lavfi -i ddagrab=output_idx=1 output.mp4Hide the mouse cursor: If you do not want the mouse pointer to appear in your recording, set
draw_mouseto 0:ffmpeg -f lavfi -i ddagrab=draw_mouse=0 output.mp4Capture a specific region: Use
offset_x,offset_y, andvideo_sizeto capture a cropped area of the screen:ffmpeg -f lavfi -i ddagrab=offset_x=100:offset_y=100:video_size=1280x720 output.mp4