🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Unable to create lossless mp4/h264 to read data from.

Started by
2 comments, last by Zurtan 3 years, 8 months ago

I am trying to encode data into an mp4 file.

So for instance, if I have the numbers 148, 102, 88, I might create an RGB pixels with those values.

Once I decode the frame from the mp4, I would like to read the pixels and get back those exact same values.

I thought that if I compress mp4 with lossless, then it will be possible, but it seems to always give me inaccurate values.

I see that on the MSbits it's somewhat accurate, but maybe the 2 or 3 MSb, not sure.

When I tried to use 4MSb it wasn't accurate as well.

Is there a way to encode bits into an MP4/H264 and be able to get an exact read of them?

I am reading the mp4 using DOM Video Element, and into a THREE.Texture.

Perhaps something there it's breaking.

If I create a THREE.DataTexture from a png, that is one of the frames used to create the mp4, then I do get the exact values I expect.

I don't think I am filtering the texture or something similar.

This mean that if I pass a texture from a png through the entire pipeline of my code, then it works well, but if pass a texture from an mp4, that was suppose to be lossless, it doesn't.

I think that maybe even a lossless mp4 doesn't show colors accurately, because it use YUV representation?

Advertisement

are you following a tutorial somewhere? which one ?

you haven't actually said how you're encoding

you haven't actually said how you're decoding

if it is yuv data you've got then maybe you need to convert to rgb:

https://www.codeproject.com/articles/402391/rgb-to-yuv-conversion-with-different-chroma-sampli

Until then ?

Ok, I made progress.

The issue with convert YUV to RGB and back to YUV, is that the color space of YUV is different from the color space of RGB.

So given both YUV is 24 bit and RGB is 24 bit, there is no 1:1 function from one to the other.

That means that even if you use 24 bit to YUV, and use lossless compression for your h264 video, you are still going to lose infromation when you convert back to 24 bit RGB.

My solution was to have RGB word values as gray, so RGB encode about 6 bits, heh. Because even if you only use gray levels, there is a certain level of quantization information loss.

You could also use different color per channel, but the quantization is linearly dependent between R, G and B, so you can't just apply quantization rounding on each channel separately.

If R is 16 and B is 0, the quantization of R is different than if R is 16 and B is 255.

The bright blue values “overshadow” the low Red values. while if there is only low red, you can still get less quantization.

So my solution is to just use gray values right now.

Now I have the issue that the file size is big.

This topic is closed to new replies.

Advertisement