openjpeg icon indicating copy to clipboard operation
openjpeg copied to clipboard

how to compress a yuv420 raw data using opj_compress in lossless

Open duankong opened this issue 5 years ago • 2 comments

I coule compress a yuv444 raw data with this code in lossless

ffmpeg  -y -i image -pix_fmt yuvj444p source.yuv

cp source.yuv source.raw

opj_compress -i source.raw -o temp.jp2 -F '%s,%s,%s,%s,u@1x1:1x1:1x1' % (width, height, 3, 8) -r 1 

opj_decompress -i temp.jp2-o decoded.raw

cp decode.raw decode.yuv

but when i change the sampling mode into yuv420

ffmpeg  -y -i image -pix_fmt yuvj420p source420.yuv

cp source420.yuv source420.raw

opj_compress -i source420.raw -o temp.jp2 -F '%s,%s,%s,%s,u@1x1:2x2:2x2' % (width, height, 3, 8) -r 1 

opj_decompress -i temp.jp2-o decoded.raw

cp decode.raw decode.yuv
  • I know the decoded.raw is in 444 format. I try to convert it to 420 sampling ,but it is not lossless with source420.yuv.

  • I also try to expand source420.yuv to 444 format ,but it is not lossless with decoded.yuv.

  • In a word:I can't get a lossless result.

Note: I caculate the psnr between source.yuv/souce420.yuv and decode.yuv with ffmpeg

duankong avatar Aug 31 '20 17:08 duankong

I try to this code below

ffmpeg  -y -i image -pix_fmt yuvj420p source420.yuv

cp source420.yuv source420.raw

opj_compress -i source420.raw -o temp.jp2 -F '%s,%s,%s,%s,u@1x1:2x2:2x2' % (width, height, 3, 8) -r 1 

opj_decompress -i temp.jp2-o decoded.ppm

ffmpeg  -y -i decoded.ppm-pix_fmt yuvj420p decoded420.yuv
  • It's different to decode into a ppm file and then to convert it to decoded420.yuv .

But in openjpeg code stream the information of image is in YUV format? I do not certain.

  • It lossy to convert a YUV file to ppm file .

  • Also it's lossy to convert a ppm to YUV file if not in YCoCg

So the psnr between decoded420.yuv and source420.yuv is 56.66 ,it large compare the commom psnr ,may be it can be consider as lossless ? But actually ,it's not lossless. I'm not sure if the lossy cause by the convert between ppm and YUV or other problem. Or both them.

duankong avatar Aug 31 '20 17:08 duankong

  • 444 format

It is 444 full range format. j means full range. That can have all kind of problems as it is sometimes just metadata.

expand source420.yuv to 444 format

It is impossible. It is lossly convertion from 444 to 420. It is also lossy from RGB to 444 and back.

souce420.yuv and decode.yuv

Yeah, I suppose that should be lossless, but I am not sure. Can you try all of that but with yuv420p?

ValZapod avatar Dec 21 '20 13:12 ValZapod