首页 > 解决方案 > 将图像转换为 YUV 格式(不同类型:BT.601 或 BT.709)并以原始格式保存

问题描述

是否有可以将给定图像(jpg)转换为 YUV 格式并将其保存为原始数据的工具?

我尝试了 Python PIL,但找不到如何做到这一点。

感谢您的任何想法。

标签: encodecodecyuv

解决方案


您可以使用安装在大多数 Linux 发行版上并且可用于 macOS 和 Windows的ImageMagick来做到这一点。只需在终端中,您就可以运行:

convert input.jpg -depth 8 -colorspace Rec601YCbCr yuv:result.bin

或者,对于Rec709YCbCr,您可以使用:

convert input.jpg -depth 8 -colorspace Rec709YCbCr yuv:result.bin

这是该过程的一个小示例并对其进行反转:

# Create a gradient image, magenta-green, save as JPEG
convert -size 1024x768 gradient:magenta-lime input.jpg

# Convert to YUV, saving as raw YUV in "image.bin"
convert input.jpg -depth 8 -colorspace Rec601YCbCr yuv:image.bin

# Convert back from raw YUV back to JPEG to check
convert -size 1024x768 -depth 8 YUV:image.bin -set colorspace Rec601YCbCr -colorspace RGB result.jpg

推荐阅读