求助大神, FFmpeg音频解码,使用官网库,三种格式CODEC_ID_ADPCM_IMA_WAV、CODEC_ID_PCM_ALAW、CODEC_ID_AAC,只有CODEC_ID_AAC能够打开解码器(视频解码器也没有问题),另外两种音频格式打开失败,可能是参数配置错误,或者没有此类型的解码库?
avcodec_register_all();
av_register_all();
AVCodec* codec = avcodec_find_decoder(CODEC_ID_ADPCM_IMA_WAV);
//CODEC_ID_ADPCM_IMA_WAV、CODEC_ID_PCM_ALAW、CODEC_ID_AAC
if (!codec)
{
fprintf(stderr, "codec not found\n");
return ;
}
AVCodecContext *codec_ctx= avcodec_alloc_context3(codec);
//codec_ctx->sample_rate = 48000;
//codec_ctx->channels = 1;
//codec_ctx->sample_aspect_ratio.den = 25;
//codec_ctx->sample_aspect_ratio.num = 1;
//codec_ctx->sample_fmt = AV_SAMPLE_FMT_S16;
//codec_ctx->codec_type = AVMEDIA_TYPE_AUDIO;
int iRet = avcodec_open2(codec_ctx, codec, NULL);/////////////////////////////////此处失败////////////////////////////////////////
if (iRet < 0)//Error Number -22 occurred!
{
//CODEC_ID_AAC当使用此格式可以成功
fprintf(stderr, "could not open codec\n");
return ;
}
|