#pragma warning(push)
#pragma warning(disable : 4101 4244)
int ConverAudio(const char* input_file, const char* output_file, int samples_rate, int channel)
{
AVFormatContext *infmt_ctx;
unsigned int i = 0;
初始化
// avcodec_register_all();
// avdevice_register_all();
av_register_all();
infmt_ctx = av_alloc_format_context();
//打开输入文件
if(av_open_input_file(&infmt_ctx, input_file, NULL, 0, NULL)!=0)
{
//debug_string("can't open input file/n");
return -1;
}
//取出流信息
if(av_find_stream_info(infmt_ctx) <0)
{
//debug_string("can't find suitable codec parameters/n");
return -2;
}
//dump_format(infmt_ctx, 0, input_file, 0); //列出输入文件的相关流信息
// 查找音频流信息
int audioindex=-1;
for(unsigned int j = 0; j < infmt_ctx->nb_streams; j++)
{
if(infmt_ctx->streams[j]->codec->codec_type == CODEC_TYPE_AUDIO)
{
audioindex=j;
break;
}
}
if(audioindex == -1) //没有找到音频流
{
//debug_string("can't find audio stream/n");
return -3;
}
AVCodecContext *incode_ctx;
AVCodec *incodec;
incode_ctx = infmt_ctx->streams[audioindex]->codec;
//找到合适的音频解码器
incodec = avcodec_find_decoder(incode_ctx->codec_id);
if(incodec == NULL)
{
//debug_string("can't find suitable audio decoder/n");
return -4;
}
//打开该音频解码器
if(avcodec_open(incode_ctx, incodec) < 0)
{
//debug_string("can't open the audio decoder/n");
return -5;
}
输出
/* 解析输出文件的格式 */
AVOutputFormat *outfmt = guess_format(NULL, output
#pragma warning(disable : 4101 4244)
int ConverAudio(const char* input_file, const char* output_file, int samples_rate, int channel)
{
AVFormatContext *infmt_ctx;
unsigned int i = 0;
初始化
// avcodec_register_all();
// avdevice_register_all();
av_register_all();
infmt_ctx = av_alloc_format_context();
//打开输入文件
if(av_open_input_file(&infmt_ctx, input_file, NULL, 0, NULL)!=0)
{
//debug_string("can't open input file/n");
return -1;
}
//取出流信息
if(av_find_stream_info(infmt_ctx) <0)
{
//debug_string("can't find suitable codec parameters/n");
return -2;
}
//dump_format(infmt_ctx, 0, input_file, 0); //列出输入文件的相关流信息
// 查找音频流信息
int audioindex=-1;
for(unsigned int j = 0; j < infmt_ctx->nb_streams; j++)
{
if(infmt_ctx->streams[j]->codec->codec_type == CODEC_TYPE_AUDIO)
{
audioindex=j;
break;
}
}
if(audioindex == -1) //没有找到音频流
{
//debug_string("can't find audio stream/n");
return -3;
}
AVCodecContext *incode_ctx;
AVCodec *incodec;
incode_ctx = infmt_ctx->streams[audioindex]->codec;
//找到合适的音频解码器
incodec = avcodec_find_decoder(incode_ctx->codec_id);
if(incodec == NULL)
{
//debug_string("can't find suitable audio decoder/n");
return -4;
}
//打开该音频解码器
if(avcodec_open(incode_ctx, incodec) < 0)
{
//debug_string("can't open the audio decoder/n");
return -5;
}
输出
/* 解析输出文件的格式 */
AVOutputFormat *outfmt = guess_format(NULL, output