解决 av_read_frame() 文件尾(end of file)

一、问题描述

使用ffmpeg API进行h264编码时,av_read_frame()从缓存读取数据,会出现读取到文件尾的情况,截图如下:
读取文件尾截图

二、解决方案

  1. 预处理
    可参考:https://blog.csdn.net/Martin_chen2/article/details/103069058
  2. 修改探针大小
// 打开输入流时,修改探针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");
}
发布了62 篇原创文章 · 获赞 26 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/Martin_chen2/article/details/105531007
今日推荐