Community
cancel
Showing results for 
Search instead for 
Did you mean: 
stsybikov
Beginner
35 Views

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.

I 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?

I 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

CIppImage data(1920,1080,1,8,0);
data.Attach(1920,1080,1,8, YUV_4_2_0_buffer, 0);
data.Color(IC_RGB);
data.NChannels(1);
data.Format(IF_FIXED);
data.ComponentOrder(0);
data.Sampling(IS_422);

PARAMS_JPEG params;
params.nthreads = 1;
params.color = IC_RGB;
params.huffman_opt = 1;
params.mode = JPEG_BASELINE;
params.point_transform = 0;
params.predictor = 1;
params.quality = 100;
params.sampling = IS_422;
params.dct_scale = JD_1_8;
params.use_qdct = 1;
params.tmode = 1;
params.restart_interval = 1;
params.comment_size = sizeof(params..comment);

SaveImageJPEG(......);

Thank you in advance,
Sergey
0 Kudos
5 Replies
Chao_Y_Intel
Employee
35 Views


Sergey,

I see it only set as one channel data, I think this is not correctfor color image.
data.NChannels(1);

Thanks,
Chao
stsybikov
Beginner
35 Views

Hi, Chao:
Thank you for reply.

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.

Regards,
Sergey
Vladimir_Dudnik
Employee
35 Views

Hello,

You can see how to use UIC JPEG encoder if you play a bit with picnic application.

You can set nChannels to 4 only if your input uncompressed image (that you got from your harware) is actually 4-channels image.

If you want JPEG image to be compressed with 4:2:0 sampling then you need to specify IS_411 sampling (by historical reason UIC JPEG use 411 name to specify 420 sampling)

Regards,
Vladimir
stsybikov
Beginner
35 Views

Hi, Vladimir:

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?

Thank you,
Sergey
Vladimir_Dudnik
Employee
35 Views

Hi Sergey,

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.

Regards,
Vladimir