使用ffmpeg读取实时视频流时,pFormatCtx-> streams [i]-> codecpar是0x00,但pFormatCtx-> streams [i]是,我的源代码如下所示,在if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)行中出现错误
//open media file
if (avformat_open_input(&pFormatCtx, url, NULL, &avdic) != 0) {
std::cout<<"can't open the file. \n";
return;
}
//find the infomation of the stream
if (avformat_find_stream_info(pFormatCtx, NULL) < 0) {
std::cout<<"Could't find stream infomation.\n";
return;
}
//find the parameters of the video stream
int videoStream = -1;
cout<<pFormatCtx->nb_streams<<endl;
for (unsigned int i = 0; i < pFormatCtx->nb_streams; i++) {
if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
videoStream = i;
}
}
if (videoStream == -1) {
std::cout<<"Didn't find a video stream.\n"<<std::endl;
return;
}发布于 2019-12-30 02:07:14
通过将我的服务器系统升级到Ubuntu 20.04来解决这个问题,原因是旧的系统18.04不能正确地链接ffmpeg动态库
https://stackoverflow.com/questions/59502424
复制相似问题