在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就可以正常运行,估计是库的问题,请各位指点一二。
下面是代码:
#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 是声道数