使用libavcodec播放媒体时出现分段故障
Segmentation fault when media played using libavcodec
我自己尝试使用libavcodec作为后端播放媒体。我下载了ffmpeg-2.0.1并使用安装/配置、制作和安装。当我试图运行一个应用程序来播放音频文件时,我在检查第一个音频流时遇到了分段错误。我的程序就像
AVFormatContext* container = avformat_alloc_context();
if (avformat_open_input(&container, input_filename, NULL, NULL) < 0) {
die(“Could not open file”);
}
if (av_find_stream_info(container) < 0) {
die(“Could not find file info”);
}
av_dump_format(container, 0, input_filename, false);
int stream_id = -1;
int i;
for (i = 0; i < container->nb_streams; i++) {
if (container->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO) {
stream_id = i;
break;
}
}
如果(容器->流[i]->编解码器->codec_type==AVMEDIA_type_AUDIO)出现分段故障
我该怎么解决这个问题?我在ubuntu 12.04工作。
一开始不需要分配AVFormatContext
。
此外,函数av_find_stream_info
也不推荐使用,您必须将其更改为avformat_find_stream_info
:
av_register_all();
avcodec_register_all();
AVFormatContext* container = NULL;
if (avformat_open_input(&container, input_filename, NULL, NULL) < 0) {
die(“Could not open file”);
}
if (avformat_find_stream_info(container, NULL) < 0) {
die(“Could not find file info”);
}
// av_dump_format(container, 0, input_filename, false);
int stream_id = -1;
int i;
for (i = 0; i < container->nb_streams; i++) {
if (container->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO) {
stream_id = i;
break;
}
}
此外,我不确定av_dump_format
在这里是否有用。。。
编辑:你试过类似的东西吗
av_register_all();
avcodec_register_all();
AVFormatContext* container = NULL;
AVCodec *dec;
if ( avformat_open_input(&container, input_filename, NULL, NULL) < 0) {
// ERROR
}
if ( avformat_find_stream_info(container, NULL) < 0) {
// ERROR
}
/* select the audio stream */
if ( av_find_best_stream(container, AVMEDIA_TYPE_AUDIO, -1, -1, &dec, 0) < 0 ) {
// ERROR
}
相关文章:
- 分段故障(堆芯转储)矢量
- 数组的指针从不分段故障
- Windows 10-使用gtkmm-3.0库和g++[包括再现]的分段故障
- 分段故障 运行C++代码时出现 SIGSEGV
- 分段故障背包问题
- 分段故障 11,从类函数显示动态 C 字符串
- 面临分段故障 使用 ffmpeg 读取视频时,因为"pFormatCtx-> streams [i]-> codecpar"的地址0x00
- 在C++中,当指向删除和指向不同对象时,分段故障指针
- 分段故障说明
- 分段故障(核心转储)-不知道为什么
- 分段故障线程
- hiredis SET遇到分段故障
- 分段故障,合并排序算法
- 多线程程序中的分段故障和gdb回溯上的不完整信息
- 到达主C++之前分段故障
- 分段故障核心使用 IF流转储
- 使用向量的移动键盘排列(分段故障)
- 在二进制树插入和遍历期间,我得到了分段故障
- 分段故障在类之间返回整数
- C++分段故障BST