How to Read Raw YUV Video with FFmpeg
Raw YUV files contain uncompressed pixel samples without file headers or metadata describing the stream. Because there is no container to store structural information, FFmpeg cannot automatically detect the file's properties. To successfully open, convert, or play a raw YUV file, you must explicitly specify the input demuxer, pixel format, frame resolution, and frame rate before passing the input file path.
The Required Input Parameters
When parsing raw YUV, all configuration options must precede the
-i parameter to act as input options:
-f rawvideo: Forces FFmpeg to use the raw video demuxer.-pixel_format(or-pix_fmt): Defines the color subsampling and byte layout (for example,yuv420p,yuv422p, oryuv444p).-video_size(or-s): Specifies the width and height of the video in pixels (for example,1920x1080or abbreviations likehd1080).-framerate(or-r): Sets the playback and decoding frame rate in frames per second (for example,30,60, or29.97).
Basic Syntax and Examples
The standard syntax for converting a raw YUV file to an H.264 MP4 file is:
ffmpeg -f rawvideo -pixel_format yuv420p -video_size 1920x1080 -framerate 30 -i input.yuv -c:v libx264 output.mp4If you need to inspect or play the raw stream directly using
ffplay, apply the same input flags:
ffplay -f rawvideo -pixel_format yuv420p -video_size 1920x1080 -framerate 30 input.yuvSupported Formats and Verification
If you are unsure of the exact name for your target pixel format, view all available options supported by your FFmpeg installation by running:
ffmpeg -pix_fmtsEnsure that the provided resolution matches the binary file size exactly. Because raw YUV contains no padding or headers, providing incorrect dimensions or pixel formats will cause visible skewing, color corruption, or premature end-of-file errors.