How to record an agent's desktop session with FFmpeg
The gist
Record an agent's Linux desktop with FFmpeg's x11grab device at a low, fixed frame rate, encode with x264 at a fast preset, and save the screenshot and action of every step beside the video. The video shows what happened between steps; the per-step log shows exactly what the model saw.
Words: VMForAI editors / Out / Fixed up / 3 min
Recording an agent's desktop session means capturing the screen to a video file for the whole task, alongside a log of every screenshot and action. FFmpeg can do the capture on any X display, including Xvfb, with one command.
How do I record an X display with FFmpeg?
Record an X display with the x11grab input device, which "allows one to capture a region of an X11 display" (FFmpeg devices, read 2026-11-26):
ffmpeg -y -f x11grab -framerate 5 -video_size 1920x1080 -i :99 \
-c:v libx264 -preset veryfast -pix_fmt yuv420p session.mp4
The input is the display name (here Xvfb's :99). FFmpeg's own example is ffmpeg -f x11grab -framerate 25 -video_size cif -i :0.0 out.mpg, and adding +X,Y after the display, as in :0.0+10,20, captures a region starting at that offset. -y will "Overwrite output files without asking" (ffmpeg manual, read 2026-11-26).
Which x11grab options matter for agent recordings?
Four options decide what the recording shows (FFmpeg devices, read 2026-11-26):
Table: x11grab options for agent recordings
| Option | Documented default | Setting for agents |
|---|---|---|
framerate | ntsc, "corresponding to a frame rate of 30000/1001" | Set low and fixed, for example 2 to 5 |
video_size | "the full desktop or window" | Set to the screen size, so every file is the same shape |
draw_mouse | 1 (the pointer is drawn) | Keep it: misclicks are easier to see |
window_id | 0, the whole screen (root window) | Keep the whole screen; dialogs open outside the app window |
follow_mouse and show_region are for people recording a part of a large screen; agent desktops are usually recorded whole.
How do I choose the encoder settings?
Choose a fast x264 preset so the encoder keeps up without taking processor time from the agent. x264 is "free software library and application for encoding video streams into the H.264/MPEG-4 AVC compression format" (x264, read 2026-11-26). Its presets, from fastest to slowest, are ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow and placebo, and its tunings include stillimage and zerolatency (x264.h, read 2026-11-26). In FFmpeg, libx264's crf option sets "the quality for constant quality mode" (FFmpeg codecs, read 2026-11-26).
Desktop video is mostly still, with small changes, so a low frame rate and a constant-quality setting keep files small. Measure the size on your own tasks: it depends on how much of the screen changes.
How do I start and stop the recording from a harness?
Start the recording before the task's first step and stop it after the last, so the file covers setup, the agent's work and the final state the grader reads.
- Start FFmpeg in the background with its own process group, and keep its process ID.
- Run the task.
- Stop FFmpeg with SIGINT (the same as pressing Ctrl+C), or give it a duration with
-t, so it writes the end of the file. - Check the file plays and has the expected length before the desktop is reset.
OSWorld's in-VM server follows this pattern: it has /start_recording and /end_recording endpoints that run an FFmpeg recording and return the video file (OSWorld server main.py, read 2026-11-26).
What should I save besides the video?
Save the per-step record, because the video does not show what the model was given.
- The screenshot sent to the model, at the size it was sent, for every step.
- The action the model returned, and the scaled coordinates actually sent to the screen.
- Timestamps for both, so a step can be found in the video.
- The screen settings: size, depth and scaling, as described in screen resolution and DPI for computer-use agents.
Screenshots can contain whatever the agent opened, including personal data and secrets typed into forms. Store recordings with the same access rules as the data the tasks use, and delete them on a schedule.
How do I take a single screenshot with FFmpeg?
Take a single frame by stopping after one: -frames:v 1, where -frames means "Stop writing to the stream after framecount frames" (ffmpeg manual).
ffmpeg -y -f x11grab -video_size 1920x1080 -i :99 -frames:v 1 step-001.png
What we read for this article
- FFmpeg devices, read 2026-11-26
- ffmpeg manual, read 2026-11-26
- FFmpeg codecs, read 2026-11-26
- x264, read 2026-11-26
- x264.h, mirror of the x264 source, read 2026-11-26
- OSWorld server main.py, read 2026-11-26
Asked
What frame rate should I record an agent desktop at?
Lower than for a person. x11grab's default is ntsc, which is 30000/1001 frames a second; agents act every few seconds, so a few frames a second usually shows every change. Set -framerate explicitly so every recording uses the same rate.
Does x11grab record the mouse pointer?
Yes by default. FFmpeg's draw_mouse option defaults to 1; set it to 0 to leave the pointer out. Keep it in for agent recordings, because where the pointer was is often the question.
How do I stop an FFmpeg recording cleanly?
Send it SIGINT, the signal Ctrl+C sends, or give it a duration with -t, so it finishes writing the file. Check that the file plays before the desktop is reset.
Is a screen recording enough to debug an agent?
No. The model acted on the screenshots it was sent, possibly resized, at the moment of each step. Save those images and the actions with timestamps; use the video for what happened between them.