Friday 15 July 2016

Convert RAW Audio into AAC Encoded Audio using FFMPEG

AAC - Advanced Audio Codec.

Download FAAC Source code from https://sourceforge.net/projects/faac/

Header File
<faac.h>

Variables
faacEncHandle codec;
faacEncConfigurationPtr conf;
unsigned long* one;
unsigned long* two;

Initialize and configure faac

/* AAC Audio FFMPEG */
one = (unsigned long *)calloc(1,((sizeof(unsigned long))+(32 - 1))/(32)*(32));
if (one == NULL)
{
        printf("Failed to allocate audio output buffer\n");
        return;
}
two = (unsigned long *)calloc(1,((sizeof(unsigned long))+(32 - 1))/(32)*(32));
if (two == NULL)
{
        FREE(one)
                printf("Failed to allocate audio output buffer\n");
        return;
}

codec=faacEncOpen(SampleRate, 1, one, two);
if(!codec){
        printf("Something went wrong");
        FREE(one)
                FREE(two)
                return;
}

conf=faacEncGetCurrentConfiguration(codec);

/* Here you can change configure as per your Requirment
**
MPEG ID's
MPEG2 1
MPEG4 0

AAC object types
MAIN 0
LOW  1
SSR  2
LTP  3

Input Formats
FAAC_INPUT_NULL    0
FAAC_INPUT_16BIT   1
FAAC_INPUT_24BIT   2
FAAC_INPUT_32BIT   3
FAAC_INPUT_FLOAT   4
*/
conf->inputFormat = FAAC_INPUT_16BIT;
conf->mpegVersion=MPEG4;
conf->aacObjectType=SSR;

faacEncSetConfiguration(codec,conf);

Call Encoder APIs to Encode AAC from RAW Audio

gAudInBuf = (unsigned char *) malloc(4000);
if (gAudInBuf == NULL)
{
        printf("Failed to allocate audio input buffer\n");
        break;
}


vdSize=faacEncEncode(codec,(int*)gAudInBuf, *one, adBuffer, *two);

Close faac Encoder module and Free Memory

faacEncClose(codec);
FREE(one)
FREE(two)

No comments:

Post a Comment