[Libav-user] AAC encoding error

Justin justin-zhao at qq.com
Sat Apr 13 09:14:35 CEST 2013


Hi,
   The following short program can reproduce the problem. 
   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.
 
====================program=========================
#include "libavutil\Rational.h"
#include "libavutil\opt.h"
#include "libavutil\Imgutils.h"
#include "libswscale\Swscale.h"
#include "libavcodec\avcodec.h"
#include "libswresample\Swresample.h"
 
main()
{
//===============================================================================================
 int i, ret, got_output;
 AVCodec *codec;
 AVCodecContext *c;
 AVFrame *frame; 
 AVPacket pkt;
 AVDictionary *opts = NULL;
 uint8_t *srcdata[2];
 
 avcodec_register_all();
 codec = avcodec_find_encoder(AV_CODEC_ID_AAC);
 if (!codec)  return;
 //avcodec_register(codec);
 c = avcodec_alloc_context3(codec);
 if (!c)  return;
 c->bit_rate = 32000;
 c->sample_rate    = 22050;
 c->channel_layout = AV_CH_LAYOUT_STEREO;
 c->channels       = av_get_channel_layout_nb_channels(c->channel_layout);
 //c->frame_size = 1024;
 c->sample_fmt = AV_SAMPLE_FMT_FLTP;

 // open it 
 av_dict_set(&opts, "strict", "experimental", 0);
 ret = avcodec_open2(c, codec, &opts);
 if (ret < 0)
  return;
 av_dict_free(&opts);
 
 frame = avcodec_alloc_frame();
 if (!frame)
    return;
 frame->nb_samples     = c->frame_size;
 frame->format         = c->sample_fmt;
 frame->channel_layout = c->channel_layout;
 
 srcdata[0] = (uint8_t *)malloc(4*c->frame_size);
 srcdata[1] = (uint8_t *)malloc(4*c->frame_size);
 memset(srcdata[0], 0, 4*c->frame_size);
 memset(srcdata[1], 0, 4*c->frame_size);
 frame->data[0] = srcdata[0];
 frame->data[1] = srcdata[1];
 
 for(i=0; i<2; i++)
 {
  av_init_packet(&pkt);
  pkt.data = NULL;    // packet data will be allocated by the encoder
  pkt.size = 0;
  /* encode the samples */
  ret = avcodec_encode_audio2(c, &pkt, frame, &got_output);
  av_free_packet(&pkt);
 }
}
------------------
Best Regards,
 Justin


 




------------------ Original ------------------
From:  "andrey.krieger.utkin"<andrey.krieger.utkin at gmail.com>;
Date:  Fri, Apr 12, 2013 08:30 PM
To:  "Justin"<justin-zhao at qq.com>; 
Cc:  "This list is about using libavcodec, libavformat, libavutil,libavdevice and libavfilter."<libav-user at ffmpeg.org>; 
Subject:  Re: [Libav-user] AAC encoding error



It would be easier to help you if you provide short but complete
compilable (i.e. with main() and so on) snippet reproducing your
problem.
_______________________________________________
Libav-user mailing list
Libav-user at ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130413/393381d6/attachment.html>


More information about the Libav-user mailing list