Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何从ffmpeg中打开的文件中获取流信息?_C++_Qt_Video_Ffmpeg - Fatal编程技术网

C++ 如何从ffmpeg中打开的文件中获取流信息?

C++ 如何从ffmpeg中打开的文件中获取流信息?,c++,qt,video,ffmpeg,C++,Qt,Video,Ffmpeg,我正在尝试使用ffmpeg读取视频文件。我的工作代码与它的旧版本相对应,并开始尝试升级到最新的构建版本,将所有不推荐的函数替换为它们的实际类似函数 然而,我遇到了一个问题。似乎没有流被检索到,视频负载停止在轨道中 以下是我正在使用的代码: // Open video file if(avformat_open_input(&pFormatCtx, filename.toStdString().c_str(), NULL, NULL)!=0) return FIL

我正在尝试使用ffmpeg读取视频文件。我的工作代码与它的旧版本相对应,并开始尝试升级到最新的构建版本,将所有不推荐的函数替换为它们的实际类似函数

然而,我遇到了一个问题。似乎没有流被检索到,视频负载停止在轨道中

以下是我正在使用的代码:

   // 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
有两条小溪,清澈如白昼


我完全莫名其妙。请提供帮助。

如果
av\u dump\u格式
有效,但
nb\u streams
在代码中为零,我想您的库和头不匹配

av_dump_格式
也依赖于
nb_流
,从其源代码中可以看出。因此,用于
av\u dump\u格式的二进制代码可以读取
nb\u流
。您可能正在使用预编译的静态或动态avformat库,该库与
avformat.h
头版本不匹配。因此,您的代码可能会在错误的位置或类型上查找
nb\u流


确保使用的头文件与用于生成所用库的二进制文件的头文件完全匹配。

您的代码似乎很好。你能分享一个视频样本让我试试吗?我是在默认Windows附带的视频上试的。Wildlife.wmvI尝试使用相同的视频。这对我有用。问题似乎在别的地方。我正在使用最新版本的FFmpeg for Windows。pFormatCtx->nb_streams=2,这样我就可以正常地循环流了..我尝试了获取最后的ffmpeg头和二进制文件,这对我也很有效。呵呵。好吧,写下“使用最新的ffmpeg”作为我可以接受的答案。哦,伙计,你救了我一天。我想知道为什么我的代码可以在Android上运行,但在Mac上崩溃了。在链接到另一个版本的库时,我引用了不同版本的ffmpeg作为标题。
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 #0: not enough frames to estimate rate; consider increasing probesize
Input #0, asf, from 'C:/Users/Public/Videos/Sample Videos/Wildlife.wmv':
  Metadata:
    SfOriginalFPS   : 299700
    WMFSDKVersion   : 11.0.6001.7000
    WMFSDKNeeded    : 0.0.0.0000
    comment         : Footage: Small World Productions, Inc; Tourism New Zealand | Producer: Gary F. Spradling | Music: Steve Ball
    title           : Wildlife in HD
    copyright       : В© 2008 Microsoft Corporation
    IsVBR           : 0
    DeviceConformanceTemplate: AP@L3
  Duration: 00:00:30.09, start: 0.000000, bitrate: 6977 kb/s
    Stream #0:0(eng): Audio: wmav2 (a[1][0][0] / 0x0161), 44100 Hz, 2 channels, fltp, 192 kb/s
    Stream #0:1(eng): Video: vc1 (Advanced) (WVC1 / 0x31435657), yuv420p, 1280x720, 5942 kb/s, 29.97 tbr, 1k tbn, 1k tbc