Media (Intel® Video Processing Library, Intel Media SDK)
Access community support with transcoding, decoding, and encoding in applications using media tools like Intel® oneAPI Video Processing Library and Intel® Media SDK
Announcements
The Intel Media SDK project is no longer active. For continued support and access to new features, Intel Media SDK users are encouraged to read the transition guide on upgrading from Intel® Media SDK to Intel® Video Processing Library (VPL), and to move to VPL as soon as possible.
For more information, see the VPL website.

Encode monochrome picture buffer to jpeg image

sometime
Beginner
2,786 Views

Hello,

based on the sample_encode from the MSDK repository, I tried to make it generate a monochrome jpeg image by setting the output chroma format to MFX_CHROMAFORMAT_MONOCHROME.

This does not work and terminates with the error MFX_ERR_INVALID_PARAM.

How can I use MSDK or oneAPI to encode gray scale images to JPEG?

Thank you.

0 Kudos
1 Solution
Mark_L_Intel1
Moderator
2,526 Views

Hi Nico,


Here is the advice from dev team, in order to use monochrome frame buffer for JPEG encode, you need to make changes to the following settings in sample_encode:


m_mfxVppParams.vpp.Out.ChromaFormat = MFX_CHROMAFORMAT_MONOCHROME;


m_mfxEncParams.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_MONOCHROME;


Mark Liu


View solution in original post

0 Kudos
7 Replies
VaradJ_Intel
Moderator
2,753 Views

Hello,

Please can you provide following information.

  1. Your MediaSDK Version
  2. Which operating system are you using?
  3. What is the format of Input image, would it be possible to share the input image/video with us?
  4. Also can you share us your code snippet so we could reproduce this?

sometime
Beginner
2,712 Views

Hello VaradJ_intel,

Thank you for your reply.

1.) Media SDK version is 1.34, hardware is Intel Core i7-9700
2.) Operating system is Windows 10 Pro version 20H2
3.) The original image is an 8 Bit per pixel single channel gray JPEG named original.jpg in the attachments.

I decoded the original image to original.yuv contained in the attached original.yuv.zip (zipped because .yuv attachment is not allowed).
I called the sample_encode with these parameters: jpeg -q 75 -i original.yuv -o encoded_by_sample_encode.jpg -w 768 -h 240, the result is attached encoded_by_sample_encode.jpg.

The sample_encode does exactly what I need. It encodes an image to a gray single channel 8 Bit per pixel JPEG very fast. This encoding speed is very useful to the company I work for. The speed is why we would like to use Intel hardware to encode images to JPEG if we can make use of the hardware.

I just need to change the input of the sample_encode from a 3 channel 24 Bit per pixel YUV uncompressed image file to a single channel 8 Bit per pixel gray uncompressed buffer.

4.) I try to describe how I modified the sample_encode files, but I cannot share all of the code I use.
I use a propietary software JPEG decoder from the company I work for, so I cannot share this code.
It just decodes a single channel gray JPEG image to a std::vector<unsigned char> buffer and I know this part of the code works fine.

Now this buffer is used a function based on the main function of sample_encode.cpp as seen in attached main.cpp from code_snippets.zip. I used the same parameters that the original sample_encode uses. I set breakpoints in the original sample_encode and copied all parameters to the modified code as seen in main.cpp.

I changed the pipeline_encode and sample_encode files to use a buffer as input.

For some reason when I run this code it creates a 24 Bit per pixel JPEG image with a green color as seen in encoded_by_sample_encode_modified_to_read_from_buffer_encodeFourCC_NV12.jpg.

So I see the image is created as a color image, that is why I try to force the output chroma format to MFX_CHROMAFORMAT_MONOCHROME as seen in pipeline_encode_chroma.cpp.
When I run this code the line sts = m_pmfxENC->EncodeFrameAsync(In.pCtrl, In.pSurface, &pTask->mfxBS, &pTask->EncSyncP); in pipeline_encode.cpp sets sts to MFX_ERR_INVALID_VIDEO_PARAM (-15).


So I see MSDK can encode single channel gray JPEG images using the hardware.
I would like to reproduce this result with a single channel 8 Bit per pixel gray buffer instead of a YUV 3 channel 24 Bit per pixel file as input.

1.) How do I need to set the parameters to encode a single channel buffer to a single channel JPEG image?
1.1) Which values should I use for input FourCC and output FourCC?
1.2) Which values should I use for input chroma format and output chroma format?
1.3) Which other parameters do I need to set?

Thank you very much.

0 Kudos
VaradJ_Intel
Moderator
2,669 Views

Thanks for sharing the details, we are checking on this internally.

Thank you.

 

0 Kudos
Mark_L_Intel1
Moderator
2,588 Views

Hi Nico,


Thanks for the information, we have created an internal request to investigate this issue.


I will keep you updated with the progress.


Mark


0 Kudos
Mark_L_Intel1
Moderator
2,527 Views

Hi Nico,


Here is the advice from dev team, in order to use monochrome frame buffer for JPEG encode, you need to make changes to the following settings in sample_encode:


m_mfxVppParams.vpp.Out.ChromaFormat = MFX_CHROMAFORMAT_MONOCHROME;


m_mfxEncParams.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_MONOCHROME;


Mark Liu


0 Kudos
sometime
Beginner
2,497 Views

Hi Mark,

Your suggestion works to fix my problem.

Thank you very much.

0 Kudos
Mark_L_Intel1
Moderator
2,403 Views

Hi Nico,


Thanks and glad to know this helps.


Mark


0 Kudos
Reply