Unable to encode YUV4:2:0 data to color JPEG image
I have video streaming (YUV 4:2:0 1920x1080) that comes from hardware. I
was able to encode and muxing this video to MPEG2, MPEG4 and H.264
file, but I have the problem to save a single frame as jpeg file.
have buffer with raw YUV 4:2:0 video frame (1920x1080) and using a
sample code from UIC jpeg I only was able to encode the data as
image with GRAY color. I tried to manipulate with different
configuration and parameters but the image file has 0 size or if the
file doesn't have 0 bytes size when I try to open the image I receive
the message that the file can't be opened because the file appears to be
damaged, corrupted, or is too large.
Any ideas what could be wrong?
tried to use the SaveImageJPEG functions from jpeg.cpp without changes and play
around with data that I am passing to it. This is the sample of one of
my try code before using SaveImageJPEG function
I changed NChannels to 4 so now I am able to open image without any problem and properties show me 32 bit depth. But right now the content of it is garbage. Any idea what I is wrong with parameters. Once again if I used color as IC_GRAY the image is fine.
My data is coming from hardware in the form of YUV420 1920x1080P video frame so I did encoding of video to H.264, MPEG2 and MPEG4. The files are pretty good, but I didn't analyze them in details because I am still in process of IPP evaluation.
Right now I am trying to save image as JPEG file from data of single frame. When I used parameters IS_411 and IC_GRAY the image is garbaged. But when I switched from IS_411 to IS_422 sampling the image content is fine. My idea was that in my case I have to use IS_422 sampling. I played around with 411 but I didn't receive the normal content of image. Is it some kind of specific parameter that I have to pay attension on?
The UIC JPEG encoder will access image data in memory in the way which depends on how you describe the memory buffer. For the same image width and height 3channel image will take less memory than 4-channel image. If you mistakenly describe you image format then encoder may not correctly access data (that seems to be reason for throubles with 411 sampling you mentioned).
Note, UIC framework assume that image with Gray color will take single color channel and image with single color channel can't be subsampled neither with 411 sampling factors nor 422 sampling factors.
In order to properly use UIC JPEG encoder you need to correctly specify actual parameters of your input (uncompressed) image and also specify desired parameters of your output (compressed) image. I would recommend you to play a little bit with UIC picnic application, where you can see what options are available for JPEG encoder and how they affect resulting image.