ffmpeg接收rtsp流異常問題

今天使用ffmpeg接收rtsp流轉mat做人臉識別時碰到了一個問題,就是使用 avformat_open_input 打開rtsp url時一直出現段錯誤,但是vlc播放url可以正常播放。百度一下發現:
ffmpeg默認rtsp使用tcp形式,–改下格式就行了。真的坑啊。。
AVFormatContext *formatCtx = NULL;
formatCtx = avformat_alloc_context();

AVDictionary* options = NULL;
av_dict_set(&options, “rtsp_transport”, “udp”, 0);

avformat_open_input(&formatCtx, pszURLPath, NULL, &options) < 0)

後續發現真正的原因是:
pformatContext=avformat_alloc_context();
if((ret=avformat_open_input(&pformatContext,url.c_str(),NULL,&optionsDict))<0)
{
std::cout<<"could not open input stream: “<<url<<”\nerror: "<<av_make_error_string(errbuf,sizeof(errbuf),ret)<<std::endl;
return false;
}

調用avformat_open_input沒有調用 avformat_alloc_context

ps: 有時候不調用這個alloc也不會出錯。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章