How to Read Raw YUV Video in FFmpeg

Reading raw YUV video files with FFmpeg requires explicitly defining the input parameters because raw files do not contain metadata headers. This guide explains how to use FFmpeg command-line options to specify the pixel format, resolution, and frame rate of your raw YUV data to ensure successful decoding and conversion.

The Core Command Structure

Because raw YUV files lack a header to describe their contents, you must tell FFmpeg how to interpret the raw stream before specifying the input file. This means the input parameters must be placed before the -i flag in your command.

The basic command template is:

ffmpeg -f rawvideo -pix_fmt [format] -s [width]x[height] -r [fps] -i input.yuv output.mp4

Parameter Breakdown


Practical Examples

Example 1: Standard 1080p YUV 4:2:0 at 30 FPS

To convert a raw YUV420p video with a resolution of 1920x1080 at 30 frames per second into an MP4 file, use the following command:

ffmpeg -f rawvideo -pix_fmt yuv420p -s 1920x1080 -r 30 -i input.yuv output.mp4

Example 2: 720p YUV 4:2:2 at 60 FPS

If your raw data uses a higher chroma subsampling format like YUV 4:2:2 at 1280x720 and 60 frames per second:

ffmpeg -f rawvideo -pix_fmt yuv422p -s 1280x720 -r 60 -i input.yuv output.mp4

Example 3: Playing Raw YUV Directly

You can also use ffplay (FFmpeg’s media player) to preview raw YUV files without converting them first. The syntax for defining input parameters remains the same:

ffplay -f rawvideo -pix_fmt yuv420p -s 1920x1080 -r 30 input.yuv

Finding Supported Pixel Formats

If you are unsure of the exact string for your pixel format, you can view all formats supported by your FFmpeg installation by running:

ffmpeg -pix_fmts