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

标签 c++ c audio ffmpeg

我在为 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/

相关文章:

c - 使用 C 中的表达式树计算后缀表达式

c - 为什么我不能像这样使用 fseek() 函数?

python - Python读取.3gpp文件

c++ - 如何修改一个类,使其只有一个成员函数,所有参数都默认?

c++ - 用单词和数字按字母顺序排列字符串

c++ - std::vector 的非静态数据成员初始值设定项/调用构造函数

C++(14)——googletest未定义标识符

c++ - C++0x 是否支持 __stdcall 或 extern "C"capture-nothing lambdas?

java - 我如何将声音从原始 View 带到 ListView 并更改它们的名称?

javascript - 记录器 : Buffer is always empty