I've successfully used the media SDK to produce a RTSP application that streams mjpeg, where the image size is fixed. However, I have a problem when trying to create jpegs for varying size images, which are patches extracted from the raw images and saved to disk.
The code below illustrates the problem, with the call to MFXInit returning MFX_ERR_UNSUPPORTED after a number of calls (usually 66 on my machine).
My application does retain the sessions so that they can be reused for images of the same size but I don't know how to handle the error below so eventually my application stops generating images.
What is the recommended approach for handling the varying image size?
S.
mfxStatus status;
mfxIMPL impl = MFX_IMPL_HARDWARE_ANY;
mfxVersion ver;
ver.Major = 1;
ver.Minor = 3;
int count = 0;
for( int height = 40; height <= 80; height += 1 )
{
for( int width = 10; width <= 40; width += 1 )
{
mfxSession* session = new mfxSession();
status = MFXInit( impl, &ver, session );
assert( status >= MFX_ERR_NONE );
mfxVideoParam video_params;
memset(&video_params, 0, sizeof(mfxVideoParam));
video_params.mfx.CodecId = MFX_CODEC_JPEG;
video_params.mfx.CodecProfile = MFX_PROFILE_JPEG_BASELINE;
//video_params.mfx.CodecLevel = MFX_LEVEL_UNKNOWN;
video_params.mfx.TargetUsage = MFX_TARGETUSAGE_BALANCED;
video_params.mfx.Quality = 20;
video_params.mfx.Interleaved = MFX_SCANTYPE_INTERLEAVED;
video_params.mfx.FrameInfo.FourCC = MFX_FOURCC_YV12;
video_params.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
video_params.mfx.FrameInfo.Width = width;
video_params.mfx.FrameInfo.Height = height;
video_params.mfx.FrameInfo.CropW = width;
video_params.mfx.FrameInfo.CropH = height;
video_params.mfx.FrameInfo.FrameRateExtD = 1;
video_params.mfx.FrameInfo.FrameRateExtN = 30;
video_params.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
video_params.mfx.RestartInterval = 0;
video_params.IOPattern = MFX_IOPATTERN_IN_SYSTEM_MEMORY;
video_params.AsyncDepth = 4;
video_params.mfx.BufferSizeInKB = MSDK_ALIGN32(width)*MSDK_ALIGN32(height)* 2 / 1000;
memset(video_params.mfx.reserved5, 0, sizeof(video_params.mfx.reserved5));
status = MFXVideoENCODE_Query( *session, &video_params, &video_params );
assert( status >= MFX_ERR_NONE );
status = MFXVideoENCODE_Init( *session, &video_params );
assert( status >= MFX_ERR_NONE );
vcl_cout << ++count << " : "<< height << " x "<< width << vcl_endl;
}
}