[Libav-user] avcodec_encode_audio() usage

Marlon Reid Marlon at scansoft.co.za
Wed Oct 12 08:05:44 CEST 2011


Hi,

I have a small application that takes a raw pcm stream, encodes it to
mp3 and streams it to something like VLC. I am however havinging issues
with encoding my raw pcm stream. The problem is that my outbuf from
avcodec_encode_audio() is always  uninitialized.  It is as if
avcodec_encode_audio() never modifies outbuf.
  
In any case, here is my function


 	 	 	
	 Code:

unsigned char* CEncoder::encode_audio_frame(unsigned char*
in_pcm_buffer, int in_pcm_buffer_size, unsigned char * mp3_buffer, int
*out_size, std::string encoding)
{

AVCodec *codec;
AVCodecContext *c= NULL;
int outbuf_size;
uint8_t *outbuf;

avcodec_init();
avcodec_register_all();

codec = avcodec_find_encoder(CODEC_ID_MP3);
c = avcodec_alloc_context3(codec);

/* put sample parameters */
c->bit_rate = 64000;
c->sample_rate = SAMPLE_RATE;
c->channels = NUM_CHANNELS;
c->sample_fmt = AV_SAMPLE_FMT_S16;

avcodec_open(c, codec)
frame_size = c->frame_size;
outbuf_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;  
 uint8_t * outbuf = new uint8_t [ outbuf_size ] ;

/* encode the samples */
*out_size = avcodec_encode_audio(c, outbuf, outbuf_size,
(short*)in_pcm_buffer);

return outbuf;
}
 
I suspect that I am using the avcodec_encode_audio() incorrectly.  Any
assistance will be great.
 
Thanks
	
	 	 	
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20111012/f7933e9f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 807 bytes
Desc: spacer.gif
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20111012/f7933e9f/attachment.gif>


More information about the Libav-user mailing list