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 to stdout.

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 (usually 1) without capturing audio (none). Run ffmpeg -f avfoundation -list_devices true -i "" to confirm your screen index.

Key Considerations

  • Suppressing Diagnostic Logs: FFmpeg outputs progress and diagnostic information to stderr by default, leaving stdout clean for binary video data. To completely silence log messages so they do not interfere with scripts, append -loglevel quiet or -loglevel error.
  • Low Latency Encoding: Use -preset ultrafast and -tune zerolatency when encoding with libx264 to 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 -.