将图像转换为 YUV 格式(不同类型:BT.601 或 BT.709)并以原始格式保存
convert image to YUV format (different types: BT.601 or BT.709) and save it in the raw format
有没有工具可以将给定的图片(jpg)转换成YUV格式并保存为原始数据?
我尝试了 Python PIL,但没找到如何做到这一点。
感谢任何想法。
您可以使用 ImageMagick 来做到这一点,它安装在大多数 Linux 发行版上并且适用于 macOS 和 Windows。就在终端,你可以 运行:
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
使用 ffmpeg 从 jpg 转换为 yuv
ffmpeg -i filename.jpg -pixel_format yuv420p -s 656x500 filename.yuv
-pixel_format
可以是 yuv420p
或 yuv422p
或 yuv444p
-s
是jpg的分辨率
查看
ffplay -f rawvideo -pixel_format yuv420p -video_size 656x500 -i filename.yuv
如果视频大小不准确,您会看到乱码。
有没有工具可以将给定的图片(jpg)转换成YUV格式并保存为原始数据?
我尝试了 Python PIL,但没找到如何做到这一点。
感谢任何想法。
您可以使用 ImageMagick 来做到这一点,它安装在大多数 Linux 发行版上并且适用于 macOS 和 Windows。就在终端,你可以 运行:
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
使用 ffmpeg 从 jpg 转换为 yuv
ffmpeg -i filename.jpg -pixel_format yuv420p -s 656x500 filename.yuv
-pixel_format
可以是 yuv420p
或 yuv422p
或 yuv444p
-s
是jpg的分辨率
查看
ffplay -f rawvideo -pixel_format yuv420p -video_size 656x500 -i filename.yuv
如果视频大小不准确,您会看到乱码。