在wav转aac时出以下错误:
Audio encoding
[NULL @ 00392440] Codec is experimental but experimental codecs are not enabled,
try -strict -2
could not open codec
感觉好像是编译的时候没有把一些解码的库也编译进去一样。求高手解答啊。
我编译库的选项是 ./configure --enable-shared --disable-static --enbla-memalign-hack
感觉代码应该没什么问题,因为用从网上下载的SDK就可以正常运行,估计是库的问题,请各位指点一二。
下面是代码:
- C/C++ code
#include <stdlib.h>#include <stdio.h>#include <string.h>#include <math.h>extern "C"{//#include <libavutil/imgutils.h>//#include <libavutil/opt.h>#include <libavcodec/avcodec.h>#include <libavutil/mathematics.h>//#include <libavutil/samplefmt.h>};extern "C"{#pragma comment (lib, "Ws2_32.lib") #pragma comment (lib, "avcodec.lib")#pragma comment (lib, "avdevice.lib")#pragma comment (lib, "avfilter.lib")#pragma comment (lib, "avformat.lib")#pragma comment (lib, "avutil.lib")//#pragma comment (lib, "swresample.lib")#pragma comment (lib, "swscale.lib")}#define INBUF_SIZE 4096#define AUDIO_INBUF_SIZE 20480#define AUDIO_REFILL_THRESH 4096/* * Audio decoding. */void audio_encode_example(const char * inputfilename ,const char *outputfilename){ AVCodec *codec; AVCodecContext *c= NULL; int frame_size, out_size, outbuf_size; FILE * fin,*fout; short *samples; uint8_t *outbuf; int numberframe = 0; int size = 0; int FRAME_READ= 0; printf("Audio encoding\n"); /* find the MP2 encoder */ codec = avcodec_find_encoder(CODEC_ID_AAC); if (!codec) { fprintf(stderr, "codec not found\n"); exit(1); } c= avcodec_alloc_context(); /* put sample parameters */ c->bit_rate = 64000; c->sample_rate = 44100; c->channels = 2; /* open it */ if (avcodec_open(c, codec) < 0) { fprintf(stderr, "could not open codec\n"); exit(1); } /* the codec gives us the frame size, in samples */ frame_size = c->frame_size; samples = (short *)malloc(frame_size * 2 * c->channels); //* 2 是因为 一般PCM数据都是16bit的 ,c->channels 是声道数 FRAME_READ = frame_size * 2 * c->channels; outbuf_size = 10000; outbuf = (uint8_t *)malloc(outbuf_size); fin = fopen(inputfilename, "rb+"); if (!fin) { fprintf(stderr, "could not open %s\n", inputfilename); exit(1); } fout = fopen(outputfilename, "wb"); if (!fout) { fprintf(stderr, "could not open %s\n", outputfilename); exit(1); } for(;;) { size = fread(samples, 1,FRAME_READ , fin); if (size == 0) { break; } /* encode the samples */ out_size = avcodec_encode_audio(c, outbuf, outbuf_size, samples); fwrite(outbuf, 1, out_size, fout); numberframe ++ ; printf("save frame %d\n",numberframe); } fclose(fout); free(outbuf); free(samples); avcodec_close(c); av_free(c);}int main(){ const char *EncodeOutputFilename_Audio; const char *EncodeInputFilename_Audio; EncodeInputFilename_Audio = "11.WAV"; EncodeOutputFilename_Audio = "22.AAC";// avcodec_init(); //首先,main函数中一开始会去调用avcodec_init()函数,该函数的作用是初始化libavcodec,而我们在使用avcodec编解码库时,该函数必须被调用。 avcodec_register_all();//注册所有的编解码器(codecs),解析器(parsers)以及码流过滤器(bitstream filters)。当然我们也可以使用个别的注册函数来注册我们所要支持的格式。 audio_encode_example(EncodeInputFilename_Audio,EncodeOutputFilename_Audio); //编码 return getchar();}
------解决方案--------------------------------------------------------
谢谢你你提供解决方法。帮顶。。。