使用ffmpeg進行264編碼時,得到的文件如下:

編碼后包含B幀
考慮到后續(xù)是需要直播的,所以不希望有B幀,應(yīng)該怎么處理呢?
分析代碼發(fā)現(xiàn):
AVCodecContext *pCodecCtx = NULL;
...
pCodecCtx->max_b_frames = 1;
pCodecCtx->pix_fmt = AV_PIX_FMT_YUV420P;
pCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO;
其中有個參數(shù)max_b_frames,它是干什么的呢?
/**
* maximum number of B-frames between non-B-frames
* Note: The output will be delayed by max_b_frames+1 relative to the input.
* - encoding: Set by user.
* - decoding: unused
*/
從注釋中可以看出它指的是兩個非B幀之間的B幀的最大數(shù)目。
將其修改為0:
pCodecCtx->max_b_frames = 0;
再次進行編碼,文件如下:

264編碼不包含B幀