使用FFmpeg SDK将.flv转换为mp3的问题



我使用FFmpeg SDK以编程方式将视频转换为mp3。

我这样读取视频的音频帧:

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);     
}

从输入的视频文件解码音频工作正常。当我尝试对mp3帧进行编码时,出现了这个问题:

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);
  }     
}
我得到以下控制台输出:
[libmp3lame] inadequate AVFrame plane padding

只发生在。flv文件中,代码适用于。mp4文件。知道错误信息是什么意思吗?

谢谢

包含错误消息的源代码在这里:http://ffmpeg.org/doxygen/trunk/libmp3lame_8c-source.html。相关消息来源说:

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

FFALIGN被定义为

#define FFALIGN (x,a)(((x)+(a)-1)&~((a)-1))

最新更新