You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

YUV422转TIFF与PNG格式时RGB值存在差异的技术咨询

Why Do RGB Values Differ Between FFmpeg and ImageMagick Conversions from YUV422?

Let’s break down why you’re seeing discrepancies between the two tools, and fix the issue step by step:

1. The Critical Mistake in Your ImageMagick Command

First off, your ImageMagick commands are using pal:input.yuv—that’s a big problem. The pal: prefix tells ImageMagick to interpret the input as a palette-indexed image, not raw YUV422 data. This means it’s completely misreading your UYVY bytes, leading to incorrect color conversions right out the gate.

You need to replace pal: with uyvy: to explicitly specify the correct YUV422 format:

# Corrected ImageMagick commands
magick -size "972x972" uyvy:input.yuv output.png
magick -size "972x972" uyvy:input.yuv output.tiff

This alone should bring your results much closer to FFmpeg’s output.

2. YCbCr-to-RGB Conversion Parameter Mismatches

Even with the correct format prefix, FFmpeg and ImageMagick might default to different conversion rules for YCbCr → RGB. The key variables here are:

  • Color space matrix: BT.601 (standard for SD video) vs BT.709 (HD video)
  • Color range: Full (0-255, typical for computer graphics) vs Limited (16-235, typical for broadcast video)

Standardize Parameters for Both Tools

To eliminate differences, explicitly set these parameters in both commands:

For FFmpeg:

Specify the color space and range to match your source (assuming your CMOS sensor outputs full-range BT.601):

ffmpeg -pix_fmt uyvy422 -s 972x972 -colorspace bt601 -color_range full -i input.yuv output.png
ffmpeg -pix_fmt uyvy422 -s 972x972 -colorspace bt601 -color_range full -i input.yuv output.tiff

For ImageMagick:

Force conversion to sRGB and align with the same color range:

magick -size "972x972" uyvy:input.yuv -colorspace sRGB -define colorspace:range=full output.png
magick -size "972x972" uyvy:input.yuv -colorspace sRGB -define colorspace:range=full output.tiff

3. Verify Consistency

After making these changes, verify the output metadata to ensure alignment:

  • For ImageMagick: Use identify -verbose output.png to check the color space and range.
  • For FFmpeg: Use ffprobe output.png to confirm the same settings are applied.

What Was Happening Before?

Your original ImageMagick command was treating the YUV bytes as palette indices, which meant it was mapping each byte to a pre-defined palette color instead of performing a proper YCbCr → RGB conversion. That’s why the RGB values were wildly different from FFmpeg’s results—FFmpeg was correctly parsing the UYVY data, while ImageMagick was doing something entirely unrelated.

Once you fix the format prefix and standardize the conversion parameters, your TIFF/PNG outputs from both tools should have identical RGB values.

内容的提问来源于stack exchange,提问作者Garry

火山引擎 最新活动