遇到分段错误使用ffmpeg读取视频时,因为“ pFormatCtx->流[i]-> codecpar”的地址为0x00

时间:2019-12-27 14:53:02

标签: c++ ffmpeg

使用ffmpeg读取实时视频流时,pFormatCtx-> streams [i]-> codecpar 0x00 ,而pFormatCtx-> streams [i] 0x55555579bbc0。 我的源代码如下,其中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;
    }

1 个答案:

答案 0 :(得分:0)

通过将服务器系统升级到<a href="{% url 'calc:unit' unit.id %}">{{ unit.unit_name }}</a> 来解决此问题,原因是旧系统Ubuntu 20.04无法正确链接ffmpeg动态库