Capture RTMP Stream to Stdout Using FFmpeg on macOS
This guide provides a quick, direct solution for capturing a live RTMP network stream and piping it directly to standard output (stdout) on macOS using the FFmpeg command-line tool. You will learn the necessary installation steps, the exact command syntax, and how to format the output stream so it can be read by other applications or processes in real-time.
Step 1: Install FFmpeg on macOS
To run FFmpeg on macOS, the easiest method is to use the Homebrew package manager. If you do not have Homebrew installed, you can get it from their official site, then install FFmpeg by opening your Terminal and running:
brew install ffmpegStep 2: The Command to Capture RTMP to Stdout
To pipe an RTMP stream directly to stdout, run the following command in your Terminal:
ffmpeg -i "rtmp://example.com/live/stream_key" -c copy -f mpegts -Command Breakdown:
-i "rtmp://example.com/live/stream_key": Specifies the input URL of the source RTMP stream.-c copy: Copies the video and audio codecs without re-encoding. This minimizes CPU usage and avoids latency.-f mpegts: Forces the output format to MPEG-TS. You must use a streamable container format (likempegtsorflv) because standard containers like MP4 require a “seekable” output to write header metadata at the end of the file, which is impossible when writing to stdout.-: The single dash at the very end tells FFmpeg to direct the output payload to stdout instead of saving it to a local file.
How to Use the Stdout Stream
Because the stream is written directly to stdout, you can pipe it into another tool for playback or processing. For example, to pipe the stream directly into the FFplay media player:
ffmpeg -i "rtmp://example.com/live/stream_key" -c copy -f mpegts - | ffplay -