Stream Desktop Recording to Stdout with FFmpeg
Streaming desktop video directly to standard output
(stdout) using FFmpeg enables you to pipe real-time screen
captures directly into other applications, network streams, or
processing scripts without saving temporary files to disk. Achieving
this requires specifying your operating system's native capture device,
selecting a streamable container format that does not require
file-seeking, and targeting the standard output pipe.
Core Command Syntax
To direct FFmpeg output to stdout, replace the output
filename with - or pipe:1. Because
stdout cannot seek backwards to update file headers (as
standard MP4 files require), you must choose a streaming-friendly
container format, such as MPEG-TS (-f mpegts), Matroska
(-f matroska), NUT (-f nut), or fragmented MP4
(-f mp4 -movflags frag_keyframe+empty_moov).
Platform-Specific Examples
Linux (X11)
Linux systems using the X Window System use the x11grab
input device:
ffmpeg -f x11grab -framerate 30 -video_size 1920x1080 -i :0.0 \
-c:v libx264 -preset ultrafast -tune zerolatency \
-f mpegts --f x11grab: Specifies the capture framework.-video_size 1920x1080: Defines the capture resolution.-i :0.0: Specifies the primary display server and screen.-f mpegts -: Packages the stream into an MPEG-TS container and sends it tostdout.
Windows (GDI / Desktop)
Windows uses the gdigrab device to capture the desktop
interface:
ffmpeg -f gdigrab -framerate 30 -i desktop \
-c:v libx264 -preset ultrafast -tune zerolatency \
-f mpegts pipe:1-f gdigrab: Uses the Windows Graphics Device Interface.-i desktop: Captures the entire primary display.pipe:1: Explicitly targets standard output (file descriptor 1).
macOS (AVFoundation)
macOS uses the avfoundation input framework:
ffmpeg -f avfoundation -framerate 30 -i "1:none" \
-c:v libx264 -preset ultrafast -tune zerolatency \
-f mpegts --f avfoundation: Uses Apple's multimedia framework.-i "1:none": Selects the screen capture device index (usually1) without capturing audio (none). Runffmpeg -f avfoundation -list_devices true -i ""to confirm your screen index.
Key Considerations
- Suppressing Diagnostic Logs: FFmpeg outputs
progress and diagnostic information to
stderrby default, leavingstdoutclean for binary video data. To completely silence log messages so they do not interfere with scripts, append-loglevel quietor-loglevel error. - Low Latency Encoding: Use
-preset ultrafastand-tune zerolatencywhen encoding withlibx264to prevent buffering delays between the screen capture and the output stream. - Raw Video Alternative: If downstream applications
require uncompressed frames rather than an encoded stream, specify raw
video instead:
-c:v rawvideo -pix_fmt rgb24 -f rawvideo -.