[Libav-user] AAC encoding error

Justin justin-zhao at qq.com
Mon Apr 15 04:02:40 CEST 2013


Anyway, I very appreciates you firstly. I'll continue to investigate it and expect a good luck.
 
------------------
Best Regards,
Justin


 




------------------ Original ------------------
From:  "andrey.krieger.utkin"<andrey.krieger.utkin at gmail.com>;
Date:  Mon, Apr 15, 2013 05:37 AM
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



Hi Justin,
I have just tried your code. With trivial changes to make it compile
at work fine at my linux installation, it looks as posted below.
I have to say it doesn't fail for me, it runs cleanly and returns
normal retcode 0. Valgrind does not find any failures, too. So i won't
further investigate this, as i am not really into windows.
Good luck investigating your issue.

#include "libavutil/rational.h"
#include "libavutil/opt.h"
#include "libavutil/imgutils.h"
#include "libswscale/swscale.h"
#include "libavcodec/avcodec.h"
#include "libswresample/swresample.h"
#include "libavutil/log.h"

// gcc -O0 -g -ggdb justin.c -lavcodec -o justin

main()
{
 int i, ret, got_output;

 AVCodec *codec;
 AVCodecContext *c;
 AVFrame *frame;
 AVPacket pkt;
 AVDictionary *opts = NULL;
 uint8_t *srcdata[2];

 av_log_set_level(AV_LOG_DEBUG);
 avcodec_register_all();
 codec = avcodec_find_encoder_by_name("aac");
 if (!codec)  return 1;
 c = avcodec_alloc_context3(codec);
 if (!c)  return 1;
 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->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 1;
 av_dict_free(&opts);

 frame = avcodec_alloc_frame();
 if (!frame)
    return 1;
 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);
 }
 return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130415/673a77c4/attachment.html>


More information about the Libav-user mailing list