1.简介
解码音频数据,如下图所示,把MP3或者AAC数据解码成原始的数据pcm。
![](https://i-blog.csdnimg.cn/blog_migrate/ecb80eed659baf356259336b0a7fb216.png)
2.流程
![](https://i-blog.csdnimg.cn/blog_migrate/da7dd27593d762986294e0a9dd81cf1b.png)
2.1在使用FFmpeg API之前,需要先注册API,然后才能使用API。当然,新版本的库不需要再调用下面的方法。
av_register_all()
2.2 构建输入AVFormatContext声明输入的封装结构体,通过输入文件或者流地址作为封装结构的句柄。
AVFormatContext* ifmt_ctx = NULL;
const char* inputUrl = "test.mp4";
///打开输入的流
int ret = avformat_open_input(&ifmt_ctx, inputUrl, NULL, NULL);
if (ret != 0)
{
printf("Couldn't open input stream.\n");
return -1;
}
2.3查找音频流信息,通过下面的接口与AVFormatContext中建立输入文件对应的流信息。
//查找;
if (avformat_find_stream_info(inputFmtCtx, NULL) < 0)
{
printf("Couldn't find stream information.\n");
return -1;
}
2.4查找解码器
先找到音频流索引,找到音频流,根据音频流的codec_id找到解码器。
//找到音频流索引
int audio_index