Hi I am trying to decode some Amrnb audio using the avcodec_decode_audio3 function. I want to input frame by frame and save the raw output frame by frame as well.
*int len = avcodec_decode_audio3(mpCodecContext, (short *)outbuf, &out_size, &pkt);* Now, the issue is that when I give the input of a frame of 32 bytes without the AMR header, i got the len >0, but the outsize value is always 640 that I am sure is not correct and I am also able to read the 640 values in the output buffer. When i try to extract the raw audio from my media file, using the standalone ffmpeg windows build i get a different output, which is correct. I have used the following command: *ffmpeg -i input.amr -f amr Output.raw* * * *Now, I am not sure if the output of **avcodec_decode_audio3 function **is correct or not as even if i send the bugger input say 64 byte or 128 or the whole while at one go, the output buffer size is always 640 bytes.* * * *Can someone let me know where I am doing the mistake for the same as I want the same out as the standalone .* * * *I have the sample attached which I am trying to decode also I have attached the sample code which I am using to decode.* * * * * * * *Regards* *Nitin* * * * *
sound2.amr
Description: Binary data
DecodeAudioFrame(unsigned char* input_data, int input_data_size, AudioFrame_t* decoded_frame)
{
AVPacket pkt;
FILE *f, *outfile;
uint8_t *outbuf;
uint8_t inbuf[AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
outbuf =(uint8_t*)malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
if(input_data_size+FF_INPUT_BUFFER_PADDING_SIZE>=mInBufferSize)
{
// Buffer too short, double it size
delete[] mInBuffer;
mInBufferSize=input_data_size+(2*FF_INPUT_BUFFER_PADDING_SIZE);
mInBuffer=new uint8_t[mInBufferSize];
}
memcpy(mInBuffer,input_data,input_data_size);
pkt.data = mInBuffer;
pkt.size = input_data_size;
int out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
int len = avcodec_decode_audio3(mpCodecContext, (short *)outbuf, &out_size, &pkt);
int out=0;
if(decoded_frame!=NULL && len>0 && mpCodecContext!=NULL)
{
decoded_frame->bitRate = mpCodecContext->bit_rate;
decoded_frame->channels = mpCodecContext->channels;
decoded_frame->nb_samples = mpCodecContext->bits_per_raw_sample;
decoded_frame->sampleRate = mpCodecContext->sample_rate;
decoded_frame->decoded_data = outbuf;
decoded_frame->size = out_size;
}
if (out_size > 0) {
/* if a frame has been decoded, output it */
fwrite(outbuf, 1, out_size, outfile);
}
fclose(outfile);
return len;
}_______________________________________________ Libav-user mailing list [email protected] http://ffmpeg.org/mailman/listinfo/libav-user
