<div>Hi,</div><div>   The following short program can reproduce the problem. </div><div>   Problem description: The avcodec_encode_audio2 firstly can be called sucessfully and return 0, but the got_output is 0 too. The second invoking avcodec_encode_audio2 will incur address accessing error. I very appreciates anyone who can help me, thanks very much.</div><div> </div><div>====================program=========================</div><div>#include "libavutil\Rational.h"<br>#include "libavutil\opt.h"<br>#include "libavutil\Imgutils.h"<br>#include "libswscale\Swscale.h"<br>#include "libavcodec\avcodec.h"</div><div>#include "libswresample\Swresample.h"</div><div> </div><div>main()</div><div>{<br>//===============================================================================================<br> int i, ret, got_output;<br> AVCodec *codec;<br> AVCodecContext *c;<br> AVFrame *frame; <br> AVPacket pkt;<br> AVDictionary *opts = NULL;<br> uint8_t *srcdata[2];</div><div> </div><div> avcodec_register_all();<br> codec = avcodec_find_encoder(AV_CODEC_ID_AAC);<br> if (!codec)  return;<br> //avcodec_register(codec);<br> c = avcodec_alloc_context3(codec);<br> if (!c)  return;</div><div> c->bit_rate = 32000;<br> c->sample_rate    = 22050;<br> c->channel_layout = AV_CH_LAYOUT_STEREO;<br> c->channels       = av_get_channel_layout_nb_channels(c->channel_layout);<br> //c->frame_size = 1024;<br> c->sample_fmt = AV_SAMPLE_FMT_FLTP;</div><div><br> // open it <br> av_dict_set(&opts, "strict", "experimental", 0);<br> ret = avcodec_open2(c, codec, &opts);<br> if (ret < 0)<br>  return;<br> av_dict_free(&opts);</div><div> </div><div> frame = avcodec_alloc_frame();<br> if (!frame)<br>    return;</div><div> frame->nb_samples     = c->frame_size;<br> frame->format         = c->sample_fmt;<br> frame->channel_layout = c->channel_layout;</div><div> </div><div> srcdata[0] = (uint8_t *)malloc(4*c->frame_size);<br> srcdata[1] = (uint8_t *)malloc(4*c->frame_size);<br> memset(srcdata[0], 0, 4*c->frame_size);<br> memset(srcdata[1], 0, 4*c->frame_size);</div><div> frame->data[0] = srcdata[0];<br> frame->data[1] = srcdata[1];</div><div> </div><div> for(i=0; i<2; i++)<br> {<br>  av_init_packet(&pkt);<br>  pkt.data = NULL;    // packet data will be allocated by the encoder<br>  pkt.size = 0;</div><div>  /* encode the samples */<br>  ret = avcodec_encode_audio2(c, &pkt, frame, &got_output);</div><div>  av_free_packet(&pkt);<br> }</div><div>}</div><div><div style="color: rgb(144, 144, 144); font-family: Arial Narrow; font-size: 12px;">------------------</div><div style="color: rgb(0, 0, 0); font-family: Verdana; font-size: 14px;"><div><font color="#3366ff">Best Regards,</font></div>
<div><font color="#3366ff">Justin</font></div></div></div><div> </div><div><div><br></div><div><br></div><div style="padding: 2px 0px; font-family: Arial Narrow; font-size: 12px;">------------------ Original ------------------</div><div style="background: rgb(239, 239, 239); padding: 8px; font-size: 12px;"><div><b>From: </b> "andrey.krieger.utkin"<andrey.krieger.utkin@gmail.com>;</div><div><b>Date: </b> Fri, Apr 12, 2013 08:30 PM</div><div><b>To: </b> "Justin"<justin-zhao@qq.com>; <wbr></div><div><b>Cc: </b> "This list is about using libavcodec, libavformat, libavutil,libavdevice and libavfilter."<libav-user@ffmpeg.org>; <wbr></div><div><b>Subject: </b> Re: [Libav-user] AAC encoding error</div></div><div><br></div>It would be easier to help you if you provide short but complete<br>compilable (i.e. with main() and so on) snippet reproducing your<br>problem.<br>_______________________________________________<br>Libav-user mailing list<br>Libav-user@ffmpeg.org<br>http://ffmpeg.org/mailman/listinfo/libav-user<br></div>