一、问题描述
使用ffmpeg API进行h264编码时,av_read_frame()从缓存读取数据,会出现读取到文件尾的情况,截图如下:
二、解决方案
- 预处理
可参考:https://blog.csdn.net/Martin_chen2/article/details/103069058 - 修改探针大小
// 打开输入流时,修改探针probesize的大小
pVideoFormatCtx->probesize = BYTES_PER_FRAME * 8;
pVideoFormatCtx->pb = avio;
if (avformat_open_input(&pVideoFormatCtx, "", piFmt, NULL) < 0) {
LOGD("avformat open failed.\n");
return -1;
} else {
LOGD("open stream success!\n");
}