<div class="gmail_quote">On Wed, Oct 12, 2011 at 2:05 AM, Marlon Reid <span dir="ltr"><<a href="mailto:Marlon@scansoft.co.za">Marlon@scansoft.co.za</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<u></u>



<div style="background-color:#e0e0e0;font-family:Arial;color:#000000;font-size:10pt" bgcolor="#e0e0e0">
<div dir="ltr" align="left"><font color="#005080"><font size="3" face="Trebuchet MS" color="#000000">Hi,<br><br>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<font color="#005080"><span> <font color="#000000"> uninitialized.  It 
is as if avcodec_encode_audio() never modifies 
outbuf.</font></span></font></font></font></div>
<div dir="ltr" align="left"><font color="#005080"><font size="3" face="Trebuchet MS"><font color="#000000"><span> </span><span> </span><br>In any case, here is my 
function<br><br></font></font></font></div>
<div>
<div>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
  <tbody>
  <tr>
    <td height="4" width="4"><font face="Trebuchet MS"><img alt="" src="http://ffmpeg.zeranoe.com/forum/images/spacer.gif" height="4" border="0" width="4"></font></td>
    <td width="100%"><font face="Trebuchet MS"><img alt="" src="http://ffmpeg.zeranoe.com/forum/images/spacer.gif" height="4" border="0" width="4"></font></td>
    <td height="4" width="4"><font face="Trebuchet MS"><img alt="" src="http://ffmpeg.zeranoe.com/forum/images/spacer.gif" height="4" border="0" width="4"></font></td></tr>
  <tr>
    <td><font face="Trebuchet MS"><img alt="" src="http://ffmpeg.zeranoe.com/forum/images/spacer.gif" height="4" border="0" width="3"></font></td>
    <td width="100%">
      <div><b><font face="Trebuchet MS">Code:</font></b></div>
      <div><br><font face="Trebuchet MS">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)<br>{<br><br>AVCodec *codec;<br>AVCodecContext *c= NULL;<br>int 
      outbuf_size;<br>uint8_t 
      *outbuf;<br><br>avcodec_init();<br>avcodec_register_all();<br><br>codec = 
      avcodec_find_encoder(CODEC_ID_MP3);<br>c = 
      avcodec_alloc_context3(codec);<br><br>/* put sample parameters 
      */<br>c->bit_rate = 64000;<br>c->sample_rate = 
      SAMPLE_RATE;<br>c->channels = NUM_CHANNELS;<br>c->sample_fmt = 
      AV_SAMPLE_FMT_S16;<br><br>avcodec_open(c, codec)<br>frame_size = 
      c->frame_size;<br>outbuf_size = 
      AVCODEC_MAX_AUDIO_FRAME_SIZE; <span><font color="#005080"> </font></span></font></div>
      <div><font face="Trebuchet MS"><span> </span>uint8_t * outbuf = new uint8_t<span><font color="#005080"> [ </font></span>outbuf_size<span><font color="#005080"> ] </font></span>;<br><br>/* encode the samples 
      */<br>*out_size = avcodec_encode_audio(c, outbuf, outbuf_size, 
      (short*)in_pcm_buffer);<br><br>return outbuf;<br>}</font></div>
      <div><font face="Trebuchet MS"></font> </div>
      <div><span><font face="Trebuchet MS">I suspect that I am using the avcodec_encode_audio() 
      incorrectly.  Any assistance will be great.</font></span></div>
      <div><span><font face="Trebuchet MS"></font></span> </div>
      <div><span><font face="Trebuchet MS">Thanks</font></span></div></td>
    <td><font face="Trebuchet MS"><img alt="" src="http://ffmpeg.zeranoe.com/forum/images/spacer.gif" height="4" border="0" width="3"></font></td></tr>
  <tr>
    <td height="4" width="4"><font face="Trebuchet MS"><img alt="" src="http://ffmpeg.zeranoe.com/forum/images/spacer.gif" height="4" border="0" width="4"></font></td>
    <td width="100%"><font face="Trebuchet MS"><img alt="" src="http://ffmpeg.zeranoe.com/forum/images/spacer.gif" height="4" border="0" width="4"></font></td>
    <td height="4" width="4"><font face="Trebuchet MS"><img alt="" src="http://ffmpeg.zeranoe.com/forum/images/spacer.gif" height="4" border="0" width="4"></font></td></tr></tbody></table></div></div>
</div></blockquote></div>I don't know what the issue is, but the obvious question is since you don't check if any of the functions (<font face="Trebuchet MS">avcodec_find_encoder</font>...) failed, are you sure they didn't fail?<br>