<div>Anyway, I very appreciates you firstly. I'll continue to investigate it and expect a good luck.</div><div> </div><div><div style="color: rgb(144, 144, 144); font-family: Arial Narrow; font-size: 12px;">------------------</div><div style="color: rgb(144, 144, 144); font-family: Arial Narrow; font-size: 12px;">Best Regards,</div><div style="color: rgb(0, 0, 0); font-family: Verdana; font-size: 14px;"><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> Mon, Apr 15, 2013 05:37 AM</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>Hi Justin,<br>I have just tried your code. With trivial changes to make it compile<br>at work fine at my linux installation, it looks as posted below.<br>I have to say it doesn't fail for me, it runs cleanly and returns<br>normal retcode 0. Valgrind does not find any failures, too. So i won't<br>further investigate this, as i am not really into windows.<br>Good luck investigating your issue.<br><br>#include "libavutil/rational.h"<br>#include "libavutil/opt.h"<br>#include "libavutil/imgutils.h"<br>#include "libswscale/swscale.h"<br>#include "libavcodec/avcodec.h"<br>#include "libswresample/swresample.h"<br>#include "libavutil/log.h"<br><br>// gcc -O0 -g -ggdb justin.c -lavcodec -o justin<br><br>main()<br>{<br> int i, ret, got_output;<br><br> AVCodec *codec;<br> AVCodecContext *c;<br> AVFrame *frame;<br> AVPacket pkt;<br> AVDictionary *opts = NULL;<br> uint8_t *srcdata[2];<br><br> av_log_set_level(AV_LOG_DEBUG);<br> avcodec_register_all();<br> codec = avcodec_find_encoder_by_name("aac");<br> if (!codec)  return 1;<br> c = avcodec_alloc_context3(codec);<br> if (!c)  return 1;<br> 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->sample_fmt = AV_SAMPLE_FMT_FLTP;<br><br> // open it<br> av_dict_set(&opts, "strict", "experimental", 0);<br> ret = avcodec_open2(c, codec, &opts);<br> if (ret < 0)<br>  return 1;<br> av_dict_free(&opts);<br><br> frame = avcodec_alloc_frame();<br> if (!frame)<br>    return 1;<br> frame->nb_samples     = c->frame_size;<br> frame->format         = c->sample_fmt;<br> frame->channel_layout = c->channel_layout;<br><br> 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);<br> frame->data[0] = srcdata[0];<br> frame->data[1] = srcdata[1];<br><br> for(i=0; i<2; i++)<br><br> {<br>  av_init_packet(&pkt);<br>  pkt.data = NULL;    // packet data will be allocated by the encoder<br>  pkt.size = 0;<br>  /* encode the samples */<br>  ret = avcodec_encode_audio2(c, &pkt, frame, &got_output);<br>  av_free_packet(&pkt);<br> }<br> return 0;<br>}<br></div>