您好,在为flv文件加载AVCodec时遇到问题。 (加载mp3或avi文件时似乎没有问题)

实际的错误是: [vorbis @ 0x1550aa0]缺少多余的数据。

因此,我将简化它并询问您:

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

由于我花了几个小时进行谷歌搜索,但没有成功

2)在ffmpeg avcodec_open2()的上下文中“缺少额外数据”到底是什么意思

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

#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/

10-10 08:01