【问题标题】:convert image to YUV format (different types: BT.601 or BT.709) and save it in the raw format将图像转换为 YUV 格式(不同类型:BT.601 或 BT.709)并以原始格式保存
【发布时间】:2020-08-27 15:54:43
【问题描述】:

有没有工具可以将给定的图片(jpg)转换成YUV格式并保存为原始数据?

我尝试了 Python PIL,但找不到如何执行此操作。

感谢您的任何想法。

【问题讨论】:

    标签: encode codec yuv


    【解决方案1】:

    您可以使用 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
    

    【讨论】:

    • 很高兴!祝你的项目好运。
    【解决方案2】:

    使用 ffmpeg 从 jpg 转换为 yuv

    ffmpeg -i filename.jpg -pixel_format yuv420p -s 656x500 filename.yuv
    

    -pixel_format 可以是yuv420pyuv422pyuv444p

    -s是jpg的分辨率


    查看

    ffplay -f rawvideo -pixel_format yuv420p -video_size 656x500 -i filename.yuv
    

    如果视频大小不准确,您会看到垃圾。

    【讨论】:

      猜你喜欢
      • 2017-05-04
      • 2014-01-03
      • 2016-04-06
      • 2014-10-01
      • 2011-02-17
      • 1970-01-01
      • 1970-01-01
      • 2019-04-16
      • 1970-01-01
      相关资源
      最近更新 更多