openh264-当前是否编I帧
作者:互联网
/*** @brief Encoder usage type*/
typedef enum {
CAMERA_VIDEO_REAL_TIME, ///< camera video for real-time communication
SCREEN_CONTENT_REAL_TIME, ///< screen content signal
CAMERA_VIDEO_NON_REAL_TIME,
SCREEN_CONTENT_NON_REAL_TIME,
INPUT_CONTENT_TYPE_ALL,
} EUsageType;
如上定义,视频类型主要有两种,摄像头视频和屏幕视频,决定帧类型是在DecideFrameType中,如下:
EVideoFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum, const int32_t kiDidx,bool bSkipFrameFlag) {
if (pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) {
}else{
//scene_changed_flag: RC enable && iSpatialNum == pSvcParam->iSpatialLayerNum
//bIdrPeriodFlag: RC disable || iSpatialNum != pSvcParam->iSpatialLayerNum
//pEncCtx->bEncCurFrmAsIdrFlag: 1. first frame should be IDR; 2. idr pause; 3. idr request
iFrameType = (pEncCtx->pVaa->bIdrPeriodFlag || bSceneChangeFlag
|| pParamInternal->bEncCurFrmAsIdrFlag) ? videoFrameTypeIDR : videoFrameTypeP;
......
}
}
以摄像头视频为例,主要考虑三个因素,1 场景切换,2强插I帧,3 IDR周期。
场景切换
for (int32_t j = 0; j < sLocalParam.iBlock8x8Height; j++) {
pRefTmp = pRefY;
pCurTmp = pCurY;
for (int32_t i = 0; i < sLocalParam.iBlock8x8Width; i++) {
int32_t iBlockPointX = i << 3;
int32_t iBlockPointY = j << 3;
uint8_t uiBlockIdcTmp = NO_STATIC;
int32_t iSad = m_pfSad (pCurTmp, sLocalParam.iCurStride, pRefTmp, sLocalParam.iRefStride);
}
}
主要是调用ESceneChangeIdc CWelsPreProcessVideo::DetectSceneChange (SPicture* pCurPicture, SPicture* pRefPicture)来处理,用本帧跟参考帧(前一帧?)进行运算,如上代码,主要是以8*8为单位,算SAD。最后跟阈值对比,得到场景切换的类型,如下代码:
if (m_sSceneChangeParam.iMotionBlockNum >= iSceneChangeThresholdLarge) {
m_sSceneChangeParam.eSceneChangeIdc = LARGE_CHANGED_SCENE;
} else if (m_sSceneChangeParam.iMotionBlockNum >= iSceneChangeThresholdMedium) {
m_sSceneChangeParam.eSceneChangeIdc = MEDIUM_CHANGED_SCENE;
}
强插I帧
/** Force coding IDR as follows */
int32_t ForceCodingIDR (sWelsEncCtx* pCtx,int32_t iLayerId);
编码库会向上暴露个接口ForceCodingIDR ,允许当前插入IDR帧,如下调用顺序:
ForceCodingIDR-->SetNextFrameToIDR->pParamInternal->bEncCurFrmAsIdrFlag = true;
IDR周期
为了防止错误的扩散,编码会设置GOP间隔,每个GOP的开始会编码IDR帧。
标签:REAL,int32,是否,IDR,CONTENT,sLocalParam,当前,TIME,openh264 来源: https://blog.csdn.net/evsqiezi/article/details/122625929