如何从ffmpeg中打开的文件获取流信息? [英] How to get stream info from opened file in ffmpeg?

查看:847
本文介绍了如何从ffmpeg中打开的文件获取流信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用ffmpeg读取视频文件。我有工作代码对应于它的一些旧版本,并开始尝试和升级到最新的版本,交换所有这些已弃用的功能的实际类比。

I am trying to read video file using ffmpeg. I had working code that corresponded to somewhat old version of it, and started to try and upgrade to latest build version, exchanging all those deprecated functions for their actual analogues.

但是我遇到了一个问题。没有视频流被检索,视频加载已停止播放。

However i have run into a problem. No streams seem to be retrieved and the load of video stops dead in tracks.

这里是我使用的代码:

   // 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

问题出现在 ffmpeg :: AVFormatContext * pFormatCtx 。 nb_streams字段为0,我从来没有真正进入循环,编解码器没有加载等。奇怪的是,av_dump_format给出以下输出:

The problem arises in the cycle through video streams in ffmpeg::AVFormatContext *pFormatCtx. nb_streams field is 0, and i never actually enter the cycle, and codec is not loaded etc. Strange thing is, av_dump_format gives following output:

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

并且有两个流,清除为天。

and there are 2 streams, clear as day.

我完全迷惑。请帮助。

推荐答案

如果 av_dump_format 有效, c> nb_streams 在您的代码中为零,您有不匹配的库和标题我猜。

If av_dump_format works, but nb_streams is zero in your code, you have mismatching libraries and headers I guess.

av_dump_format 也依赖于 nb_streams 看到它的来源。因此,用于 av_dump_format 的二进制代码可以读取 nb_streams 。很可能您使用的是预编译的静态或动态avformat库,它与您的 avformat.h 标题版本不匹配。因此,例如,您的代码可能在错误的位置或类型中查找 nb_streams

av_dump_format relies on nb_streams too, as can bee seen in its source. So the binary code you used for av_dump_format can read nb_streams. It is likely that you are using a precompiled static or dynamic avformat library, which does not match your avformat.h header version. Thus your code may look for nb_streams at an wrong location or type, for example.

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

Make sure you use the header files exactly matching the ones used for making the binaries of the libraries used.

这篇关于如何从ffmpeg中打开的文件获取流信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆