一 一般编码h264的时候需要设置gop size, group of picture size,意思是多少帧出现一个I帧。
这个值设置之后,编码器出帧就会严格按照这个间隔来的,那有人想要在画面运动剧烈的时候尽可能降低gop,在静态的时候增大gop,怎样做呢?
看看x264源码AVFrame结构体:
uint8_t *data[AV_NUM_DATA_POINTERS];//存放yuv数据的指针,具体怎么存放和YUV layout格式有关,像YUV420P,YUV444,YUV422等
int linesize[AV_NUM_DATA_POINTERS];//stride size,意思是上面这data对应的一行的数据长度
enum AVPictureType pict_type;//帧类型
enum AVPictureType {
AV_PICTURE_TYPE_NONE = 0, ///< Undefined
AV_PICTURE_TYPE_I, ///< Intra
AV_PICTURE_TYPE_P, ///< Predicted
AV_PICTURE_TYPE_B, ///< Bi-dir predicted
AV_PICTURE_TYPE_S, ///< S(GMC)-VOP MPEG-4
AV_PICTURE_TYPE_SI, ///< Switching Intra
AV_PICTURE_TYPE_SP, ///< Switching Predicted
AV_PICTURE_TYPE_BI, ///< BI type
};
AV_PICTURE_TYPE_NONE = 0, ///< Undefined
AV_PICTURE_TYPE_I, ///< Intra
AV_PICTURE_TYPE_P, ///< Predicted
AV_PICTURE_TYPE_B, ///< Bi-dir predicted
AV_PICTURE_TYPE_S, ///< S(GMC)-VOP MPEG-4
AV_PICTURE_TYPE_SI, ///< Switching Intra
AV_PICTURE_TYPE_SP, ///< Switching Predicted
AV_PICTURE_TYPE_BI, ///< BI type
};
可以通过上面这个域pict_type来指定编码出来的帧类型,从而实现动态的gop大小。
注意:用x264编码的时候,有一个预设参数:
av_opt_set(f_DstCodecCtx_->priv_data, "x264opts", "rc-lookahead=30", 0);
设定mb-tree位元率控制和vbv-lookahead使用的帧数。最大允许值是250。对于mb-tree部分,增加帧数带来更好的效果但也会更慢。mb-tree使用的最大缓冲值是MIN(rc-lookahead, --keyint)。上面设置为30,编码前30帧是不会出画面的。