I am trying to read a video file using ffmpeg. I had a working code that corresponded to several old versions, and started trying and updating to the latest version of the assembly, exchanging all these obsolete functions for their actual counterparts.
However, I ran into a problem. It seems that no streams are being retrieved, and the video loading stops on the tracks.
here is the code i use:
// Open video file if(avformat_open_input(&pFormatCtx, filename.toStdString().c_str(), NULL, NULL)!=0) return FILE_NOT_OPENED; // Couldn't open file // Retrieve stream information if(avformat_find_stream_info(pFormatCtx,NULL)<0) return NO_STREAM_INFO; // Couldn't find stream information // Dump information about file onto standard error av_dump_format(pFormatCtx, 0, filename.toStdString().c_str(), false); // Find the first video stream videoStream=-1; for(unsigned i=0; i<pFormatCtx->nb_streams; i++) if(pFormatCtx->streams[i]->codec->codec_type==ffmpeg::AVMEDIA_TYPE_VIDEO) { videoStream=i; break; } if(videoStream==-1) return OTHER; // Didn't find a video stream // Get a pointer to the codec context for the video stream pCodecCtx=pFormatCtx->streams[videoStream]->codec; // Find the decoder for the video stream pCodec=avcodec_find_decoder(pCodecCtx->codec_id); if(pCodec==NULL) return CODEC_NOT_FOUND; // Codec not found // Open codec if(avcodec_open2(pCodecCtx, pCodec,NULL)<0) return CODEC_NOT_OPENED; // Could not open codec
The problem occurs in the loop through the video streams in ffmpeg::AVFormatContext *pFormatCtx . The nb_streams field is 0, and I never enter the loop, and the codec does not load, etc. Strange, av_dump_format gives the following result:
License: GPL version 3 or later AVCodec version 3606372 AVFormat configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib [asf @ 004e9540] Stream
and there are 2 streams, clear as a day.
I am completely puzzled. Please, help.
Srv19 source share