一、問題描述
使用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");
}