How to Read Raw YUV Video from Stdin with FFmpeg
Reading raw YUV video data from standard input (stdin) is a powerful way to pipeline video processing in FFmpeg without creating temporary files. Because raw YUV streams do not contain headers or metadata, FFmpeg cannot automatically detect the video’s properties like resolution, frame rate, or pixel format. This guide will show you how to explicitly configure FFmpeg to receive and decode raw YUV data directly from stdin.
To read raw YUV data from stdin, you must define the input parameters
before specifying the input source. Use the hyphen symbol
(-) as the input filename to tell FFmpeg to read from
stdin.
Here is the standard command structure:
[source_command] | ffmpeg -f rawvideo -pixel_format yuv420p -video_size 1920x1080 -framerate 30 -i - output.mp4Parameter Breakdown
-f rawvideo: Forces FFmpeg to interpret the incoming stream as raw, demuxed video data.-pixel_format yuv420p(or-pix_fmt): Specifies the YUV sampling format. Common formats includeyuv420p,yuv422p, oryuyv422. You must match the exact pixel layout of your source data.-video_size 1920x1080(or-s): Defines the width and height of the video frames in pixels. Since raw streams have no metadata, FFmpeg needs this to know where each frame begins and ends.-framerate 30(or-r): Sets the frame rate of the incoming raw stream.-i -: The-ioption specifies the input, and the trailing hyphen (-) instructs FFmpeg to read this input from stdin.
Practical Example
If you have a raw YUV file named input.yuv and want to
stream it through stdin to convert it to an MP4, run:
cat input.yuv | ffmpeg -f rawvideo -pixel_format yuv420p -video_size 1280x720 -framerate 24 -i - output.mp4This configuration ensures FFmpeg accurately parses the incoming raw byte stream and processes it according to your exact specifications.