Search code examples
compressionh.264image-compression

Lossless H.264 compression of a 16-bit grayscale image


I have a 16-bit monochrome image that I need to encode it using lossless H.264.

Ideally, I would love to be able to use a 16-bit Y component, and then empty U and V components, but I believe such an implementation does not exist. On the other extreme, I would hate to be forced to split it into two 8-bit grayscale images and code two frames.

How can I get closest to coding the ideal 16:0:0 bit distribution?

Note: My original data is in YUV444 using 16 bits per component, but I can rearrange the bitplanes in any way it is needed


Solution

  • You will likely find the best results (in terms of file size) would come from putting 8 bits of the grayscale pixel into the Y and then splitting 4 bits into both the U and V channels. That way, when the remaining 2 x 4 bit U and V components are the same the YCoCg colorspace conversion should compress them down in size. The lossless method does not downsample the UV channels. As far as I know, ffmpeg is the only software that implements this encoder/decoder and so you would need to use it to do both the compression and decompression. See my other answer at this question for specific command line arguments to use.