dynamic change bitrate in CBR mode

dynamic change bitrate in CBR mode

Hi:
    I'm using the SDK(API 1.8 for linux) to change the target bitrate dynamically. When I use VBR mode, it seems to be OK, but when I use CBR mode, the Reset() function seems success(return MFX_WRN_INCOMPATIBLE_VIDEO_PARAM), and after call GetVideoParam(), the value of bitrate is what I set , but the streem contain the old bitrate, maybe I am missing something?

the key code is as follow:
Step1: Init param
mfxStatus sts = MFX_ERR_NONE;
m_EncExtParams.clear();
MSDK_ZERO_MEMORY(m_mfxEncParams);
MSDK_ZERO_MEMORY(m_EncResponse);
m_mfxEncParams.mfx.CodecId                 = MFX_CODEC_AVC;
m_mfxEncParams.mfx.TargetUsage             = m_h264param.usageTarget; // trade-off between quality and speed
m_mfxEncParams.mfx.TargetKbps              = m_h264param.bitrate; // in Kbps
m_mfxEncParams.mfx.RateControlMethod       = m_h264param.rctype;
m_mfxEncParams.mfx.FrameInfo.FrameRateExtN = m_h264param.frameN;
m_mfxEncParams.mfx.FrameInfo.FrameRateExtD = m_h264param.frameD;
m_mfxEncParams.mfx.EncodedOrder            = 0;
if ( SYSTEM_MEMORY == m_memType ) {
    m_mfxEncParams.IOPattern                = MFX_IOPATTERN_IN_SYSTEM_MEMORY;
} else {
    m_mfxEncParams.IOPattern               = MFX_IOPATTERN_IN_VIDEO_MEMORY;
}

m_mfxEncParams.mfx.FrameInfo.FourCC       = MFX_FOURCC_NV12;
m_mfxEncParams.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
m_mfxEncParams.mfx.FrameInfo.PicStruct    = m_h264param.interlace;

m_mfxEncParams.mfx.FrameInfo.Width  = MSDK_ALIGN16(m_h264param.width);
m_mfxEncParams.mfx.FrameInfo.Height = (MFX_PICSTRUCT_PROGRESSIVE == m_mfxEncParams.mfx.FrameInfo.PicStruct)?
MSDK_ALIGN16(m_h264param.height) : MSDK_ALIGN32(m_h264param.height);

printf("EncParams.FrameInfo.Width=[%d],Height=[%d]\n", m_mfxEncParams.mfx.FrameInfo.Width, m_mfxEncParams.mfx.FrameInfo.Height);

m_mfxEncParams.mfx.FrameInfo.CropX = 0;
m_mfxEncParams.mfx.FrameInfo.CropY = 0;
m_mfxEncParams.mfx.FrameInfo.CropW = m_h264param.width;
m_mfxEncParams.mfx.FrameInfo.CropH = m_h264param.height;

//mfxExtCodingOption config
// CAVLC EOF HRD
MSDK_ZERO_MEMORY(m_CodingOption);
m_CodingOption.CAVLC = MFX_CODINGOPTION_OFF;
m_CodingOption.EndOfStream = MFX_CODINGOPTION_OFF;

m_CodingOption.NalHrdConformance = MFX_CODINGOPTION_OFF;
m_mfxEncParams.mfx.RateControlMethod = MFX_RATECONTROL_VBR;
m_mfxEncParams.mfx.MaxKbps = m_mfxEncParams.mfx.TargetKbps*1.01;
//m_mfxEncParams.mfx.RateControlMethod = MFX_RATECONTROL_CBR;

m_CodingOption.Header.BufferId = MFX_EXTBUFF_CODING_OPTION;
m_CodingOption.Header.BufferSz = sizeof(m_CodingOption);
m_EncExtParams.push_back((mfxExtBuffer *)&m_CodingOption);

if (!m_EncExtParams.empty())
{
    m_mfxEncParams.ExtParam = &m_EncExtParams[0]; // vector is stored linearly in memory
    m_mfxEncParams.NumExtParam = (mfxU16)m_EncExtParams.size();
}

m_mfxEncParams.mfx.GopPicSize = 250;
m_mfxEncParams.mfx.IdrInterval = 1;

m_mfxEncParams.mfx.CodecProfile = m_h264param.profile;
if (m_h264param.profile != MFX_PROFILE_AVC_BASELINE ) {
    m_mfxEncParams.mfx.GopRefDist = m_h264param.bframes + 1;
}

m_mfxEncParams.mfx.NumRefFrame = 3;

Step2: change bitrate
mfxVideoParam oldParam;
MSDK_ZERO_MEMORY(oldParam);
mfxStatus status = m_pmfxENC->GetVideoParam(&oldParam);
oldParam.mfx.TargetKbps = bitrate_kb;
oldParam.mfx.MaxKbps = oldParam.mfx.TargetKbps*1.01; // if CBR, ignore
if (status != MFX_ERR_NONE){
    printf("+++[GetVideoParam] error status:%d [%s:%d]\n", status, __FILE__, __LINE__);
}
sts = m_pmfxENC->Reset(&oldParam);
printf("+++Reset status:%d\n", sts);
MSDK_IGNORE_MFX_STS(sts, MFX_WRN_INCOMPATIBLE_VIDEO_PARAM);
if (sts != MFX_ERR_NONE){
    printf("+++[Reset] error sts:%d [%s:%d]\n", sts, __FILE__, __LINE__);
} else {
    MSDK_ZERO_MEMORY(oldParam);
    m_pmfxENC->GetVideoParam(&oldParam);
    printf("+++After change bitrate:%dkb\n", oldParam.mfx.TargetKbps);
}

 

 

AttachmentSize
Download CBR mode.png28.89 KB
Download VBR mode.png26.88 KB
1 post / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.