Ошибка сегментации при воспроизведении мультимедиа с использованием libavcodec

Я сам пытаюсь воспроизводить мультимедиа, используя libavcodec в качестве бэкэнда. Я скачал ffmpeg-2.0.1 и установил с помощью ./configure,make и произвел установку.
При попытке запустить приложение для воспроизведения аудиофайла возникает ошибка сегментации при проверке первой аудиопотока. Моя программа похожа на

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;
}
}

Ошибка сегментации возникает в if (container-> streams [i] -> codec-> codec_type == AVMEDIA_TYPE_AUDIO)

Как я могу это исправить? Я работаю в Ubuntu 12.04.

0

Решение

Вам не нужно выделять свои 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
}
1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector