[Libav-user] avcodec_encode_audio() usage

Michael Niedermayer michaelni at gmx.at
Mon Oct 17 21:23:38 CEST 2011


On Wed, Oct 12, 2011 at 08:05:44AM +0200, Marlon Reid wrote:
> 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.

well, simply put av_log() (or printf() after #undef) at various
places and see where things go wrong
in   avcodec_encode_audio()
in MP3lame_encode_frame()

to check if all is reached and if so then what arguments go into
lame and whats wrong there

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Into a blind darkness they enter who follow after the Ignorance,
they as if into a greater darkness enter who devote themselves
to the Knowledge alone. -- Isha Upanishad
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20111017/3e7aa530/attachment.asc>


More information about the Libav-user mailing list