uclouvain / openjpeg

Official repository of the OpenJPEG project
Other
968 stars 454 forks source link

how to compress a yuv420 raw data using opj_compress in lossless #1273

Open duankong opened 4 years ago

duankong commented 4 years ago

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

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

duankong commented 4 years ago

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

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

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 YUVor other problem. Or both them.