avformat_find_stream_info不填充nb_streams和流
avformat_find_stream_info not filling out the nb_streams and streams
嗨,这是我第一次找不到已经回答的问题,所以这是我首次在这里发布内容。
我有这个代码剪辑,这是我尝试遵循我找到的一些关于获得一些基本libav功能(提取视频帧的方法)的教程。
1 #ifndef INT64_C
2 #define INT64_C(c) (c ## LL)
3 #define UINT64_C(c) (c ## ULL)
4 #endif
5
6 extern "C" {
7 #include <libavformat/avformat.h>
8 #include <libavcodec/avcodec.h>
9 #include <libavutil/avutil.h>
10 }
11 #include <iostream>
12 using namespace std;
13 #define FILENAME "/home/jon/Videos/testvideo.avi"
14
15
16 int main(int argc, char** argv)
17 {
18 av_register_all();
19 AVFormatContext * avFormatPtr = avformat_alloc_context();
20 if (avformat_open_input(&avFormatPtr, FILENAME, NULL, NULL) != 0)
21 cout<<"Error while calling avformat_open_input (probably invalid file format)"<<endl;
22 if (avformat_find_stream_info(avFormatPtr, NULL) < 0)
23 cout<<"Error while calling avformat_find_stream_info"<<endl;
24 av_dump_format(avFormatPtr,0,FILENAME,false);
25
26 cout<<"There are "<<avFormatPtr->nb_streams<<" streams"<<endl;
27 unsigned int video_codec_id = -1;
28 for (unsigned int i = 0; i < avFormatPtr->nb_streams; ++i) {
29 cout<<"loop iteration "<<i<<endl;
30 if(avFormatPtr->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
31 {
32 cout<<"Found video "<<i<<endl;
33 video_codec_id = i;
34 }
35 cout<<"debug point";
36 }
37
38 cout<<"fin"<<endl;
39}
现在的问题是,这总是分段故障,这是的输出
Input #0, avi, from '/home/jon/Videos/testvideo.avi':
Metadata:
encoder : Lavf53.21.0
Duration: 00:01:51.08, start: 0.000000, bitrate: 17129 kb/s
Stream #0.0: Video: mpeg4 (Simple Profile), yuv420p, 1920x1088 [PAR 1:1 DAR 30:17], 25 tbr, 25 tbn, 25 tbc
There are 157328928 streams
loop iteration 0
Segmentation fault (core dumped)
流部分的数量每次都会变化,这让我认为它只是指向内存中的一个随机位置,所以我想我一定对有误解
avformat_find_stream_info
现在,这在第一次循环迭代中也总是segfault,所以我想流也没有初始化。提前感谢您的帮助。
有趣的是av_dump_format()
能够正确地看到流。我能想到的一个可能的原因是你的Libav安装已经损坏了——你使用的是不同主要版本的头文件和库。
尝试打印LIBAVFORMAT_VERSION_INT
与avformat_version()
。
相关文章:
- 面临分段故障 使用 ffmpeg 读取视频时,因为"pFormatCtx-> streams [i]-> codecpar"的地址0x00
- 如何创建一个 while 循环,继续循环,直到在C++中输入'using streams'键?
- C++应用程序缺少 winrt::Windows::Storage::Streams::D ataWriter
- Introduction To C++ IO Streams
- 为什么cpplint不鼓励Streams
- Streams中的内联忽略
- 在C++std::streams中,失败后,如何获得失败原因?必需:线程安全,适用于Windows和Linux(或至少M
- 从 Windows::Storage::Streams::IBuffer 中获取字节数组
- OpenCV 3.1.0 NB分类器,将所有MNIST训练样本分类为单个类别
- GCC, std::ctype specialisation & streams
- cstdio streams vs iostream streams?
- 从网络豆到VS的转变。NB没有错误。VS找到了一些,我无法修复它们
- C++ io streams versus mmap
- C++11 File Streams
- c++ JNI在做任何IO/Streams时崩溃/挂起
- boost::streams::output过滤器的意外行为
- Including windows.storage.streams.h
- Override c++ streams
- Cython: working with C++ streams