1

我正在制作一个程序来记录和编码这个录音到 aac。我为 linux 和 libfaac 做了一个函数来完成这项工作。现在我需要为 Windows 制作这个程序。我知道我需要使用 libvo-aacenc,但我不知道要在我的代码中更改什么。你能告诉我该怎么做吗?这是我的代码。

static void encodeAac( const char *infilename,const char *filename)
{
    AVCodec *codec;
    AVCodecContext *c = NULL;
    int frame_size, i, j, out_size, outbuf_size;
    FILE *f,*fin;
    SAMPLE *samples;
    float t, tincr;
    uint8_t *outbuf;

    avcodec_register_all();                                                 //Load all codecs
    av_register_all();
    codec = avcodec_find_encoder(AV_CODEC_ID_AAC);  //Search for AAC codec
    if (!codec) {
            error("Codec not found");
    }
    c = avcodec_alloc_context();
    c->bit_rate = 64000;
    c->sample_fmt = AV_SAMPLE_FMT_S16;
    c->sample_rate = SAMPLE_RATE;
    c->channels = NUM_CHANNELS;
    c->time_base.num= 1;
    c->time_base.den= SAMPLE_RATE;
    c->profile= FF_PROFILE_AAC_MAIN;
    if (avcodec_open(c, codec) < 0) {
            error(add("","",avcodec_open(c, codec)).c_str());
            exit(1);
    }
    f = fopen(filename, "wb");
    fin=fopen(infilename,"rb");
    if (!fin) {
            error("could not open temporary file");
    }
    if (!f) {
            error("could not open output file");
    }
    std::cout << c->frame_size*c->channels << std::endl;
    samples = new SAMPLE[c->frame_size*c->channels];
    outbuf = new uint8_t[FRAMES_PER_BUFFER * NUM_CHANNELS];
    while(fread(samples,sizeof(SAMPLE),c->frame_size*c->channels,fin)){
            out_size=avcodec_encode_audio(c,outbuf,FRAMES_PER_BUFFER * NUM_CHANNELS,samples);
            fwrite(outbuf,sizeof(uint8_t),out_size,f);
    }
    for(int i=1;i<=4;i++){                          //For buffer flushing
    out_size=avcodec_encode_audio(c,outbuf,FRAMES_PER_BUFFER * NUM_CHANNELS,NULL);
    fwrite(outbuf,sizeof(uint8_t),out_size,f);
    }

    fclose(f);
    delete outbuf;
    delete samples;

    avcodec_close(c);
    av_free(c);
}
4

0 回答 0