簡介
avformat_open_input主要是探測碼流的格式,例如是H264或者FLV格式的碼流
問題
avformat_open_input函數探測ES流開銷是150毫秒,探測PS流開銷是500毫秒。avformat_open_input函數裏面已經實現了av_probe_input_buffer函數的調用,去探測AVInputFormat結構體的相關變量。所以在avformat_open_input函數之前,調用av_probe_input_buffer函數之後,就不會去探測AVInputFormat結構體
優化方向
嘗試屏蔽avformat_open_input函數,直接指定碼流的輸入格式pInputFormat,代碼如下:
pInputFormat = av_find_input_format("h264");
pFormatCtx->iformat = pInputFormat;
如果這個時候屏蔽掉avformat_open_input,圖像是條帶狀的,按照參考文獻的說法,該avformat_open_input
函數就是爲了探測AVInputFormat結構體的相關變量
最終優化方案
沒有屏蔽avformat_open_input函數,而是在調用之前指定AVInputFormat的碼流輸入格式
代碼
AVInputFormat* pInputFormat = NULL;
AVFormatContext* pFormatContext = NULL;
pFormatContext = avformat_alloc_context();
pInputFormat = av_find_input_format("h264");
if (avformat_open_input(&pFormatContext, "", InputFormat, NULL) < 0)
{
av_free(...);
avformat_free_context(...);
fprintf(stdout, "open stream failed!\n");
}
else
{
fprintf(stdout, "open stream success!\n");
}
筆記
m_pVideoc->io_ctx = avio_alloc_context(m_pAvioBuf, BUF_SIZE, 0, this, ReadStreamData, NULL, NULL);
if (avformat_open_input(&pFormatCtx, "", piFmt, NULL) < 0)
上面的ReadStreamData實際的用途是在下面打開實時流的時候,如果需要讀取數據,可以通過ReadStreamData函數獲取到幀的消息內容
而不用通過avformat_open_input函數的第二個參數傳遞url
參考
http://blog.csdn.net/leo2007608/article/details/53421528
http://blog.csdn.net/leixiaohua1020/article/details/39759163
http://blog.csdn.net/leixiaohua1020/article/details/44064715
FFmpeg avformat_open_input函數優化
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.