1. 程式人生 > >[aac @ ...] more samples than frame size (avcodec_encode_audio2)

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

back doxygen dde ext class blank \n clas avpacket

在用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; } } } // ... }

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