简体   繁体   中英

Facing Segmentation fault When reading video using ffmpeg, because the address of "pFormatCtx-> streams [i]-> codecpar" is 0x00

When reading real time video stream by using ffmpeg, pFormatCtx-> streams [i]-> codecpar is 0x00 , but pFormatCtx-> streams [i] is 0x55555579bbc0. my source code is as below where error occurs in line 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;
    }

通过将我的服务器系统升级到Ubuntu 20.04来解决这个问题,因为旧系统18.04无法正确链接 ffmpeg 动态库

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM