InterDigitalInc / CompressAI

A PyTorch library and evaluation platform for end-to-end compression research

Home Page:https://interdigitalinc.github.io/CompressAI/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I encode/decode an .rgb file or a .yuv file, please?

sddai opened this issue · comments

I tried to encode an .yuv file into .bin file, but I got the error.
the command I used is:

python ./codec.py encode ./dataset/video1_1.rgb --num_of_frames 1 --model bmshj2018-factorized --metric mse -q 1 -o ./test_rgb.bin --cuda

and I got the following error:

Traceback (most recent call last):
  File "./codec.py", line 608, in <module>
    main(sys.argv[1:])
  File "./codec.py", line 602, in main
    encode(argv)
  File "./codec.py", line 560, in encode
    _encode(
  File "./codec.py", line 381, in _encode
    out = encode_func[codec_type](input, codec_info, output)
  File "./codec.py", line 265, in encode_image
    img = load_image(input)
  File "./codec.py", line 105, in load_image
    return Image.open(filepath).convert("RGB")
  File "/root/miniconda3/lib/python3.8/site-packages/PIL/Image.py", line 3283, in open
    raise UnidentifiedImageError(msg)
PIL.UnidentifiedImageError: cannot identify image file './dataset/video1_1.rgb'

Then, I turned to encode a .yuv file by using:

python ./codec.py encode ./all_yuv/video1_1.yuv --num_of_frames 1 --model bmshj2018-factorized --metric mse -q 1 -o ./test_yuv.bin --cuda

and I got:

Traceback (most recent call last):
  File "./codec.py", line 604, in <module>
    main(sys.argv[1:])
  File "./codec.py", line 598, in main
    encode(argv)
  File "./codec.py", line 556, in encode
    _encode(
  File "./codec.py", line 382, in _encode
    out = encode_func[codec_type](input, codec_info, output)
  File "./codec.py", line 258, in encode_image
    org_seq = RawVideoSequence.from_file(input)
  File "/root/miniconda3/lib/python3.8/site-packages/compressai/datasets/rawvideo.py", line 292, in from_file
    info = get_raw_video_file_info(filename)
  File "/root/miniconda3/lib/python3.8/site-packages/compressai/datasets/rawvideo.py", line 169, in get_raw_video_file_info
    if info["bitdepth"] and info["bitdepth2"] and info["bitdepth"] != info["bitdepth2"]:
KeyError: 'bitdepth'

could you please figure that how can I encode/decode an .rgb file or a .yuv file?
Thank you very much.

Please check get_raw_video_file_info mentioned in the error. .yuv raw files don't contain any header to indicate resolution, bitdepth etc, so we usually try to include that in the filename which we parse.

@fracape thank you very much.

And another question is, if I wanted to encode an .rgb file directly, why I would get the afore mentioned error?

the command I used is:

python ./codec.py encode ./dataset/video1_1.rgb --num_of_frames 1 --model bmshj2018-factorized --metric mse -q 1 -o ./test_rgb.bin --cuda

and I got the following error:

Traceback (most recent call last):
File "./codec.py", line 608, in
main(sys.argv[1:])
File "./codec.py", line 602, in main
encode(argv)
File "./codec.py", line 560, in encode
_encode(
File "./codec.py", line 381, in _encode
out = encode_func[codec_type](input, codec_info, output)
File "./codec.py", line 265, in encode_image
img = load_image(input)
File "./codec.py", line 105, in load_image
return Image.open(filepath).convert("RGB")
File "/root/miniconda3/lib/python3.8/site-packages/PIL/Image.py", line 3283, in open
raise UnidentifiedImageError(msg)
PIL.UnidentifiedImageError: cannot identify image file './dataset/video1_1.rgb'

I don't know what .rgb is, we rely on PIL to read images, please look at their doc to check supported formats.

.rgb may refer to a .sgi file.

https://en.m.wikipedia.org/wiki/Silicon_Graphics_Image

Perhaps convert your sgi file to a more typical lossless format (e.g. PNG) via imagemagick. Alternatively, PIL may support sgi via a plugin: https://www.google.com/search?q=pil%20sgi

I think @YodaEmbedding's suggestion is safest. Closing for now