[Libav-user] codecpar returns NULL

Patrick Cusack patrickcusack at mac.com
Tue Apr 14 18:44:41 EEST 2020


I have some code that worked without issue up until now. When I pass a file path into avformat_open_input  I can create a pFormatCtx, but none of the streams have any codec information associated with them, ie pFormatCtx->streams[i]->codecpar is null. I assume that my codecs are not being opened? I know that av_register_all() is deprecated, but otherwise avformat_open_input doesn’t work. I am using 3.4.2 of ffmpeg. Any assistance is appreciated.

Patrick


    av_register_all();
    int error = avformat_open_input(&pFormatCtx, filePath, NULL, NULL);
    if(error != 0){
        char * errorString= (char*)malloc(AV_ERROR_MAX_STRING_SIZE);
        (void) av_strerror(error, errorString, AV_ERROR_MAX_STRING_SIZE);
        printf("%s\n", errorString);
        status = K_CANT_OPEN_FILE; // Couldn't open file
        return;
    }
    
    if(avformat_find_stream_info(pFormatCtx, NULL)<0){
       status = K_NO_STREAM_INFO;  //NO STREAM INFO
        return;
    }

    videoStream = -1;
    for(i = 0; i < pFormatCtx->nb_streams; i++){
        AVStream * stream = pFormatCtx->streams[i];
        if(pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {. // <—codecpar is NULL
            videoStream=i;
            break;
        }
    }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20200414/941732ae/attachment.html>


More information about the Libav-user mailing list