Capture RTMP Stream to stdout with FFmpeg

This article explains how to capture a live RTMP network stream using FFmpeg and pipe the raw media payload directly to stdout (standard output). By sending the stream directly to stdout, you can feed live video data into other command-line applications, custom scripts, or media players in real-time without writing temporary files to your disk.

To capture an RTMP stream and output it directly to stdout, use the following basic FFmpeg command structure:

ffmpeg -i rtmp://your_server_address/live/stream_key -c copy -f mpegts pipe:1

Here is a breakdown of what each parameter does in this command:

Real-World Examples

1. Piping to a Media Player (ffplay) You can verify your stdout pipe is working by sending the stream directly to another media player like ffplay:

ffmpeg -i rtmp://example.com/live/stream -c copy -f mpegts pipe:1 | ffplay -

2. Piping to a Custom Script or Tool If you are processing the stream with a custom Python or Node.js script, or a tool like WebRTC broadcasters, you can read the binary data directly from the system’s standard input:

ffmpeg -i rtmp://example.com/live/stream -c copy -f mpegts - | python3 process_stream.py

Alternative Formats

If your downstream application strictly requires the original FLV container format instead of MPEG-TS, you can change the format flag:

ffmpeg -i rtmp://example.com/live/stream -c copy -f flv -