[FFmpeg-user] Audio encode: [mp2 @ 0x29c52410] Size 1792 invalid

Unga unga888 at yahoo.com
Thu Jun 21 08:15:24 CEST 2012


> From: Unga <unga888 at yahoo.com>
> To: "ffmpeg-user at ffmpeg.org" <ffmpeg-user at ffmpeg.org>
> Cc: 
> Sent: Tuesday, June 19, 2012 4:20 PM
> Subject: Audio encode: [mp2 @ 0x29c52410] Size 1792 invalid
> 
> Hi all
> 
> I'm trying out the audio video encoding example provided with the ffmpeg 
> with avcodec_encode_audio2().
> 
> I get following error when I try to encode audio:
> [mp2 @ 0x29c52410] Size 1792 invalid
> 
> Error with the other messages:
> Audio Time base: 0.000023
> Audio frame_size: 1152
> CODEC_CAP_DELAY is NOT set.
> Audio data_size: 4608
> [mp2 @ 0x29c52410] Size 1792 invalid
> Encode frame failed -22
> 
> 
> Appreciate very much if somebody could help me to get the audio encoding to 
> work. If mp2 is old, I would like to try the vorbis.
> 
> My encoding function is basically as follows:
> 
> static void audio_encode_example(const char *filename)
> {
>     AVCodec *codec;
>     AVCodecContext *c= NULL;
>     int i, j;
>     FILE *f;
>     short *samples;
>     float t, tincr;
>     uint8_t *outbuf;
>     
>     AVFrame *frame;
>     AVPacket outPkt;
>     int ret, got_packet = 0;
>     double time_base;
>     int64_t pts;
>     int data_size = 0;
> 
>     codec = avcodec_find_encoder(CODEC_ID_MP2);
>     c = avcodec_alloc_context3(codec);
> 
>     c->bit_rate = 64000;
>     c->sample_rate = 44100;
>     c->channels = 2;
>     c->sample_fmt = AV_SAMPLE_FMT_S16;
> 
>     if (avcodec_open2(c, codec, NULL) < 0) {
>         fprintf(stderr, "could not open codec\n");
>         exit(1);
>     }
> 
>     frame= avcodec_alloc_frame();
>     av_init_packet(&outPkt);
> 
>     frame->nb_samples = c->frame_size;    
> 
>     data_size = av_samples_get_buffer_size(NULL, c->channels, 
> frame->nb_samples, c->sample_fmt, 1);
>     samples = malloc(data_size);
> 
> 
>     // Fill samples here
> 
>     outPkt.data = NULL;                
>     avcodec_fill_audio_frame(frame, c->channels, c->sample_fmt,
>                              (uint8_t *)samples,
>                              data_size, 1);
>                 
>     if ((ret = avcodec_encode_audio2(c, &outPkt, frame, &got_packet)) 
> < 0)
>        {
>         fprintf(stderr, "Encode frame failed %d\n", ret);
>         exit(1);
>        }
> 
> }
> 
> 
> Many thanks in advance.
> 
> Best regards
> Unga
> 
I tried with CODEC_ID_FLAC, then I get following:
Audio Time base: 0.000023
Audio frame_size: 4608
CODEC_CAP_DELAY is set.
Audio data_size: 18432
[flac @ 0x29c52410] Size 1310 invalid
Encode frame failed -22

Is it some thing not set right?

Best regards
Unga


More information about the ffmpeg-user mailing list