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: “< return false;
}

调用avformat_open_input没有调用 avformat_alloc_context

ps: 有时候不调用这个alloc也不会出错。

你可能感兴趣的:(ffmpeg)