FFmpeg Convert RGB to YUV422p Using Scale Filter
Converting RGB video to the YUV422p pixel format is a crucial step
for ensuring compatibility with professional video editing software,
hardware players, and broadcast pipelines. This article provides a
direct, step-by-step guide on how to perform this color space conversion
using the FFmpeg scale filter, which ensures high-quality
resampling and prevents color shift issues during the transition.
The Basic Conversion Command
To convert an RGB video to YUV422p without changing the original
resolution, use the scale filter by setting the output
format parameter. Run the following command in your terminal:
ffmpeg -i input_rgb.mp4 -vf "scale=format=yuv422p" output_yuv422p.mp4Command Breakdown
-i input_rgb.mp4: Specifies the path to your source RGB video file.-vf "scale=format=yuv422p": Applies the video filter (-vf). Thescalefilter is invoked, and theformatoption explicitly forces the output chroma subsampling to YUV 4:2:2 planar (8-bit).output_yuv422p.mp4: The resulting converted video file.
Simultaneous Scaling and Format Conversion
If you need to resize the video dimensions (width and height) while
converting the color space, you can define the resolution parameters
directly within the same scale filter:
ffmpeg -i input_rgb.mp4 -vf "scale=1920:1080:format=yuv422p" output_yuv422p.mp4In this command, 1920:1080 resizes the video to Full HD,
while format=yuv422p ensures the output is correctly
formatted.
Why Use the Scale Filter Instead of -pix_fmt?
While FFmpeg allows color conversion using the simpler
-pix_fmt yuv422p flag, utilizing the scale
filter is highly recommended for professional workflows. The
scale filter:
- Prevents Color Shifts: It allows you to define
specific scaling algorithms (like
lanczosorbicubic) and color matrices (such as BT.709 for HD video) to maintain visual fidelity. - Enables Single-Pass Processing: You can resize, crop, and convert pixel formats in a single, efficient rendering step, saving processing time and avoiding generation loss.