在用FFmpeg对音频进行编码的时候报如下错误:

[aac @ 000001cfc2717200] more samples than frame size (avcodec_encode_audio2)

 

 

原因:我们编码器的 frame_size 比采集到的 frame->nb_samples 小:

官方源代码链接:http://ffmpeg.org/doxygen/trunk/encode_8c_source.html

int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
    AVPacket *avpkt,
    const AVFrame *frame,
    int *got_packet_ptr)
{

    // ...

     /* check for valid frame size */
    if (frame) {
        if (avctx->codec->capabilities & AV_CODEC_CAP_SMALL_LAST_FRAME) {
            if (frame->nb_samples > avctx->frame_size) {
                av_log(avctx, AV_LOG_ERROR, "more samples than frame size (avcodec_encode_audio2)\n");
                ret = AVERROR(EINVAL);
                goto end;
            }
        }
        else if (!(avctx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)) {
            if (frame->nb_samples < avctx->frame_size &&
                !avctx->internal->last_audio_frame) {
                ret = pad_last_frame(avctx, &padded_frame, frame);
                if (ret < 0)
                    goto end;

                frame = padded_frame;
                avctx->internal->last_audio_frame = 1;
            }

            if (frame->nb_samples != avctx->frame_size) {
                av_log(avctx, AV_LOG_ERROR, "nb_samples (%d) != frame_size (%d) (avcodec_encode_audio2)\n", frame->nb_samples, avctx->frame_size);
                ret = AVERROR(EINVAL);
                goto end;
            }
        }
    }

    // ...
}

 

相关文章:

  • 2021-04-13
  • 2021-08-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
  • 2022-03-10
  • 2021-08-04
  • 2021-07-24
相关资源
相似解决方案