FFmpeg Pipe Raw Video to Another Tool macOS
This article provides a quick and practical guide on how to use
FFmpeg on macOS to stream raw, uncompressed video directly to another
command-line tool. You will learn how to configure FFmpeg to output to
standard output (stdout), format the raw video stream
correctly, and pipe that data into a receiving application in
real-time.
To pipe raw video from FFmpeg to another tool on macOS, you must
direct FFmpeg’s output to stdout using a single hyphen
(-) and specify the raw video format. Because raw video
contains no container or header metadata, you must also explicitly
define the pixel format so the receiving tool knows how to decode the
stream.
The Basic Command Structure
The standard command template for piping raw video is as follows:
ffmpeg -i input.mp4 -f rawvideo -pix_fmt yuv420p - | destination_toolCommand Breakdown
-i input.mp4: Specifies your input source file (or stream).-f rawvideo: Forces FFmpeg to demux/mux the output as raw, uncompressed video frames.-pix_fmt yuv420p: Sets the pixel format. Popular options includeyuv420p,rgb24, oruyvy422. The receiving tool must support the pixel format you choose.-: Representsstdout. This tells FFmpeg to write the video data directly to the terminal’s output stream instead of saving it to a file.|: The Unix pipe operator, which redirects the stdout of FFmpeg to the stdin of the next command.destination_tool: The command-line utility or script receiving the raw video stream.
Practical Example: Verification with FFplay
You can verify that your pipe is working correctly by piping the raw
video directly into ffplay (the media player bundled with
FFmpeg). Because raw video has no header, you must tell the receiving
player the resolution, pixel format, and framerate of the incoming
stream:
ffmpeg -i input.mp4 -f rawvideo -pix_fmt rgb24 - | ffplay -f rawvideo -pixel_format rgb24 -video_size 1920x1080 -framerate 30 -Piping to Custom Scripts (Python/Node.js)
If you are piping raw video into a custom processing script (such as
a Python script using OpenCV), your script must read from standard input
(sys.stdin or sys.stdin.buffer).
For example, to pipe raw RGB frames to a Python script:
ffmpeg -i input.mp4 -f rawvideo -pix_fmt rgb24 - | python3 process_stream.pyInside your Python script, you would read the exact number of bytes
required for each frame based on the resolution and pixel format (e.g.,
width * height * 3 bytes per frame for 24-bit RGB).