如何从ffmpeg打开的文件中获取流信息
How to get stream info from opened file in ffmpeg?
我正在尝试使用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
问题出现在ffmpeg::AVFormatContext *pFormatCtx
的视频流循环中。Nb_streams字段是0,我从来没有真正进入循环,编解码器没有加载等。奇怪的是,av_dump_format给出如下输出:
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
有两条小溪,清澈如白昼。
我完全困惑了。请帮助。如果av_dump_format
工作,但nb_streams
是零在你的代码,你有不匹配的库和头我猜。
av_dump_format
也依赖于nb_streams
,从它的源代码可以看出。因此,用于av_dump_format
的二进制代码可以读取nb_streams
。很可能您正在使用预编译的静态或动态avformat库,它与您的avformat.h
头版本不匹配。因此,您的代码可能会在错误的位置或类型中查找nb_streams
。
确保您使用的头文件与用于生成所使用库的二进制文件的头文件完全匹配。
相关文章:
- C++ - 忽略并从其他文件获取数据
- 为什么从文件获取图标时应用程序有时会崩溃?
- 如何在 c++ 窗口中将参数和返回的退出值传递到批处理文件/从批处理文件获取返回的退出值
- Qt .pro 文件获取 Qtkit 名称
- 提升属性树:如何使用xml文件获取子树的子级
- 从C 中的二进制文件获取整数值时
- 如何在Windows上绕过主机文件获取真实的IP地址
- 如何使用 CPP/C# 从 VHDX 文件获取文件(或文件系统)
- 从读取到对象指针数组的文件获取段错误
- 是否可以从IOS项目中的cpp文件获取文件路径
- 将数据从头文件获取到源文件中的非成员函数中
- 从两个不同的文件获取输入时,输入会发生变化
- 从文件 C++ 获取整数
- 通过在 C++ 中使用发布模式二进制文件获取崩溃原因
- C++ 将值从文件获取到数组中
- 使用HTTP上载文件.获取错误:-HttpSendReuest 12005
- 正在从外部文件获取输入
- 读/写同一个文件(获取gmon.out)
- 从二进制文件获取输入时发生访问冲突错误
- 从特定文件获取函数指针