Capture RTMP Stream to stdout with FFmpeg
This guide explains how to pull an RTMP live stream and pipe its
media payload directly to standard output (stdout) using
FFmpeg. By configuring stream-friendly muxing formats and disabling
interactive prompts or log pollution, you can easily ingest RTMP feeds
into downstream utilities, custom scripts, or external processing
pipelines in real time.
The Basic Command
To read an RTMP stream and output the raw or repackaged data to
stdout, use the following standard syntax:
ffmpeg -i "rtmp://source.server.com/live/stream_key" -c copy -f flv -In FFmpeg, a hyphen (-) or pipe:1
designates standard output as the target destination.
Essential Flags Explained
When streaming directly to stdout, specific parameters
are required to ensure continuous, uninterrupted data delivery:
-i "rtmp://...": Specifies the RTMP source URL.-c copy: Copies the incoming video and audio streams directly without re-encoding, preserving the original payload and minimizing CPU usage.-f <format>: Defines the output container format. Standard output cannot seek backwards, meaning the container format must support non-seekable streaming. Common streamable formats include:flv: Standard wrapper for RTMP content (H.264 + AAC).mpegts: Ideal for broadcast-oriented stream processing.h264: Raw H.264 elementary video stream (no audio).nut: Lightweight container format supporting arbitrary codecs.
-: Representsstdout.
Handling Log Output
By default, FFmpeg prints banner, configuration, and transcoding
statistics to stderr. While stderr is distinct
from stdout in most shell environments, suppressing
unnecessary logs prevents performance degradation and keeps output
pipelines clean:
ffmpeg -loglevel error -i "rtmp://source.server.com/live/stream_key" -c copy -f flv -Using -loglevel error ensures only critical failures are
logged.
Common Implementation Scenarios
1. Piping into Another Command
To pipe an RTMP stream directly to a media player such as MPV or VLC without saving to disk:
ffmpeg -loglevel error -i "rtmp://source.server.com/live/stream_key" -c copy -f flv - | mpv -2. Extracting Raw H.264 Video Only
If a downstream decoder requires raw Network Abstraction Layer (NAL) units without container metadata, strip the audio and output elementary H.264 data:
ffmpeg -i "rtmp://source.server.com/live/stream_key" -an -c:v copy -f h264 -3. Operating in Listen Mode
If FFmpeg should act as the RTMP receiver waiting for an external
broadcaster (such as OBS) to push data to it, add the
-listen 1 flag before the input:
ffmpeg -listen 1 -i "rtmp://0.0.0.0:1935/live/stream_key" -c copy -f mpegts -