【发布时间】:2020-08-27 15:54:43
【问题描述】:
有没有工具可以将给定的图片(jpg)转换成YUV格式并保存为原始数据?
我尝试了 Python PIL,但找不到如何执行此操作。
感谢您的任何想法。
【问题讨论】:
有没有工具可以将给定的图片(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
如果视频大小不准确,您会看到垃圾。
【讨论】: