Question

I'm using the FFmpeg SDK to programmatically convert videos to mp3.

I read the audio frames of the video this way:

while(av_read_frame(pFromCtx, &pkt) >= 0) 
{
    if(pkt.stream_index == audioStreamIndex) 
    {        
        avcodec_get_frame_defaults(frame);
        got_frame = 0;              
        ret = avcodec_decode_audio4(pCodecCtx, frame, &got_frame, &pkt);                
        if (ret < 0) {
            av_log(NULL, AV_LOG_ERROR, "Error decoding audio frame.\n");            
            continue;
        }

        if(got_frame) 
        {                    
          // Write the decoded audio frame           
          write_audio_frame(pToCtx, pToCtx->streams[pToCtx->nb_streams-1], frame);                    
        }                        
    }
    av_free_packet(&pkt);     
}

Decoding the audio from the input video file works fine. The problem occurs when I try to encode a mp3 frame:

static void write_audio_frame(AVFormatContext *oc, AVStream *st, AVFrame *frame)
{
  AVCodecContext *enc = st->codec;
  AVPacket pkt;
  int got_packet = 0; 
  int ret = 0; 
  av_init_packet(&pkt);
  pkt.data = NULL; 
  pkt.size = 0; 

  ret = avcodec_encode_audio2(enc, &pkt, frame, &got_packet);

  if (ret < 0) {
      // PROBLEM    
      fprintf(stderr, "Error encoding audio frame. \n");
      exit(1);
  }     
}

I get the following console output:

[libmp3lame] inadequate AVFrame plane padding

The only happens with .flv files, the code works fine for .mp4 files. Any clue what the error message means?

Thanks

Était-ce utile?

La solution

The source code containing the error message is here: http://ffmpeg.org/doxygen/trunk/libmp3lame_8c-source.html. The relevant source says:

if (frame->linesize[0] < 4 * FFALIGN(frame->nb_samples, 8)) {
    av_log(avctx, AV_LOG_ERROR, "inadequate AVFrame plane padding\n");
    return AVERROR(EINVAL);
}

FFALIGN is defined as

#define FFALIGN (x,a)(((x)+(a)-1)&~((a)-1))
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top