H264 Encoding Problems at some resolutions

H264 Encoding Problems at some resolutions

Hi,

I use the MediaSDK 2012 to encode video with the H264 encoder. After several tests, I noticed problems with some resolutions.

I always check that video width and height are multiple of 16, but at some resolutions, the video encoding produces diagonal lines. Please see the jpeg attached:

My tests show that the encoding works well with the following resolutions:
640x480, 1600x1200, 320x240, 352x288, 160x128, 1280x720

It has the line problems at these resolutions:
720x480, 208x160.

Here are the configuration I use of the encoder (for 720x480 - I just change resolution and bitrate for other resolutions):

m_MFXEncParams.mfx.CodecId = MFX_CODEC_AVC;
m_MFXEncParams.mfx.TargetUsage = MFX_TARGETUSAGE_BEST_SPEED ;
m_MFXEncParams.mfx.RateControlMethod = MFX_RATECONTROL_VBR;
m_MFXEncParams.mfx.GopRefDist = 1;
m_MFXEncParams.AsyncDepth = 1;
m_MFXEncParams.mfx.FrameInfo.FourCC = MFX_FOURCC_NV12;
m_MFXEncParams.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420;

m_MFXEncParams.IOPattern = MFX_IOPATTERN_IN_SYSTEM_MEMORY;

mfxExtBuffer *extBuffersInit[1];
mfxExtCodingOption extCO;

memset( &extCO, 0, sizeof( extCO)) ;
extCO.Header.BufferId = MFX_EXTBUFF_CODING_OPTION;
extCO.Header.BufferSz = sizeof(mfxExtCodingOption);
extCO.MaxDecFrameBuffering = 1;
extBuffersInit[0] = reinterpret_cast(&extCO);
m_MFXEncParams.NumExtParam = 1;
m_MFXEncParams.ExtParam = extBuffersInit;
m_MFXEncParams.mfx.NumRefFrame = 1;

m_MFXEncParams.mfx.FrameInfo.Width = 720 ;
m_MFXEncParams.mfx.FrameInfo.Height = 480 ;

m_MFXEncParams.mfx.FrameInfo.CropX = 0;
m_MFXEncParams.mfx.FrameInfo.CropY = 0;
m_MFXEncParams.mfx.FrameInfo.CropW = 720 ;
m_MFXEncParams.mfx.FrameInfo.CropH = 480 ;

m_MFXEncParams.mfx.TargetKbps = (mfxU16)512 ; // in Kbps
m_MFXEncParams.mfx.FrameInfo.FrameRateExtN = (mfxU32)15 ;
m_MFXEncParams.mfx.FrameInfo.FrameRateExtD = 1 ;
m_MFXEncParams.mfx.GopPicSize = m_MFXEncParams.mfx.FrameInfo.FrameRateExtN*4 ;

m_MFXEncParams.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;

Benjamin

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hi Benjamin,

We have not seen any issues like that here. As a sanity check I also verified with a similar setup as yours and did not encounter any issues.

I suspect your issue may be related to raw yuv input content not actually being of the specified dimension, such as 720x480? Could you please double check by regenerating the yuv content or checking the content in a yuv viewer tool?

Also, looking at your code it seems the variables"extBuffersInit" and "extCO" are created in the encoder init scope (function)? Is that correct? If so I instead suggest you put mfxExtBuffer *extBuffersInit[1]; mfxExtCodingOption extCO;in the owning class to make sure they do not get destroyed when going out of scope.

If you still have issues could you please provide some more details about your system setup, such as driver version, did you use SW or HW encode etc.

Regards,
Petter

Hi Petter,

I finally solve my problem! I was missing the pitch member of the mfxSurface for both encoding and decoding, I was only using the real width of the video. I added the management of the pitch and it works well now.

Thank you,

Benjamin

Login to leave a comment.