gpt4 book ai didi

c++ - "Vorbis Extradata missing"尝试获取有关编解码器的流信息时

转载 作者:搜寻专家 更新时间:2023-10-31 01:48:10 24 4
gpt4 key购买 nike

我在为 flv 文件加载 AVCodec 时遇到问题。 (加载mp3或者avi文件好像没有问题)

实际错误是:

[vorbis @ 0x1550aa0] Extradata missing.

所以我会保持简单并问你:

  1. 有人熟悉这种类型的错误吗?

    因为我花了几个小时谷歌搜索但没有成功

  2. ffmpeg avcodec_open2() 的上下文中,“extradata missing” 到底是什么意思?

你可以在下面看到我的代码:

#ifdef __cplusplus
#define __STDC_CONSTANT_MACROS
#ifdef _STDINT_H
#undef _STDINT_H
#endif
#endif

#include <stdint.h>
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
#include <libavutil/samplefmt.h>
}
#include <stdio.h>

int main(int argc, char * argv[])
{
if(argc < 2)
{
printf("you need to specify filename \n");
return -1;
}
av_register_all();
avcodec_register_all();

//opening a file
AVFormatContext *avFormatContext = NULL;
int ret = avformat_open_input(&avFormatContext, argv[1], NULL, NULL);
if (ret < 0)
return -2; // Couldn't open file

//print some basic info
printf("num of streams = %u\n", *(&avFormatContext->nb_streams));
printf("filename = %s\n", *(&avFormatContext->filename));
printf("start time = %ld \n", *(&avFormatContext->start_time));
printf("duration = %ld \n", *(&avFormatContext->duration));
printf("bit rate = %d\n", *(&avFormatContext->bit_rate));
printf("audio codec id = %d \n\n\n", *(&avFormatContext->audio_codec_id));

AVCodecContext * pCodecContext;
int audioStreamId = -1;
for(int i = 0; i < avFormatContext->nb_streams; i++)
{
if(avFormatContext->streams[i]->codec->codec_type ==
AVMEDIA_TYPE_AUDIO)//CODEC_TYPE_AUDIO)
{
audioStreamId = i;
break;
}
}

if(audioStreamId == -1)
return -3; //Didn't find an audio stream

printf("audioStreamId = %d \n", audioStreamId);

pCodecContext = avFormatContext->streams[audioStreamId]->codec;
if(pCodecContext == NULL)
return -10;

//The stream's information about the codec is in what
//we call the "codec context." This contains all the information
//about the codec that the stream is using, and now we have a pointer to it.
//But we still have to find the actual codec and open it:

AVCodec *pCodec;
AVDictionary *options;
//Find the decoder for the audio stream
pCodec = avcodec_find_decoder(pCodecContext->codec_id);

printf("TEST codec name = %s fullName = %s\n",
pCodec->name, pCodec->long_name);

if(pCodec == NULL)
return -4; //Codec not found
//Open codec
//avcodec_open2 - This function is not thread safe!
//Prior to using this function the context has to be allocated with
// avcodec_alloc_context3().
pCodecContext = avcodec_alloc_context3(pCodec);

printf("test 0\n");
if(pCodecContext == NULL)
return -5; //Could not allocate audio codec context

printf("test 1\n");
if(avcodec_open2(pCodecContext, pCodec, NULL) < 0)
return -6; //Couldn't open codec

printf("test 2\n");

avformat_close_input(&avFormatContext);

return 0;
}

这些是我输出屏幕的最后几行:

TEST codec id = 86021
t0
t1
[vorbis @ 0x19eeaa0] Extradata missing.

最佳答案

调用avformat_open_input()后需要调用avformat_find_stream_info()

关于c++ - "Vorbis Extradata missing"尝试获取有关编解码器的流信息时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18219364/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com