How to Output Raw Video from FFmpeg to stdout
To output raw video data from FFmpeg directly to standard output (stdout), you need to instruct FFmpeg to use the raw video muxer and direct the output file path to the system’s standard output stream. This guide explains how to construct the correct FFmpeg command using the pipe protocol and format flags, ensuring your raw video frames are seamlessly piped into other applications or scripts.
The Standard Command Structure
To output raw video to stdout, use the hyphen character
(-) or pipe:1 as the output destination. You
must also specify the raw video format using the
-f rawvideo flag and define the desired pixel format.
Here is the standard command:
ffmpeg -i input.mp4 -f rawvideo -pix_fmt rgb24 -Alternatively, you can use the explicit pipe syntax:
ffmpeg -i input.mp4 -f rawvideo -pix_fmt yuv420p pipe:1Parameter Breakdown
-i input.mp4: Specifies the source video file.-f rawvideo: Forces FFmpeg to use the raw video muxer, stripping away any container format (like MP4, MKV, or AVI) and leaving only raw pixel data.-pix_fmt rgb24: Sets the pixel format. For raw video, defining the pixel format is crucial because the receiving application needs to know how to interpret the byte stream. Common options include:rgb24: 24-bit raw RGB (8 bits per channel).rgba: 32-bit raw RGBA (includes alpha channel).yuv420p: Raw YUV 4:2:0 planar data.
-(orpipe:1): Redirects the output stream from a file to stdout.
Preventing Console Log Corruption
By default, FFmpeg writes its configuration details, progress reports, and errors to standard error (stderr). This naturally keeps the raw video data on stdout clean. However, to ensure no accidental log data interferes with your stream, you can disable the banner and lower the log level:
ffmpeg -hide_banner -loglevel panic -i input.mp4 -f rawvideo -pix_fmt rgb24 --hide_banner: Suppresses the build information and library versions.-loglevel panic: Instructs FFmpeg to only print info to stderr if the program is about to crash, keeping stderr completely silent during normal operations.
Practical Example: Piping to Another Program
When piping raw video to another program, the receiving application
must be configured to read from standard input (stdin) and
know the exact dimensions and pixel format of the video, as raw video
contains no header metadata.
For example, to pipe raw video from FFmpeg directly into another player like FFplay:
ffmpeg -i input.mp4 -f rawvideo -pix_fmt yuv420p - | ffplay -f rawvideo -pixel_format yuv420p -video_size 1920x1080 -