X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fencode.c;h=d81b32b98382ee7731d6bb5312464c98a3eef610;hb=fd3ee7a92e9227ee44e2a0d837ba9879959b15d7;hp=0ebd8dd6a55ea99bf7a4012df918a4e9ca537cbe;hpb=c9ed7f002492c7901f8638d8765bf4532dc2900a;p=ffmpeg diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 0ebd8dd6a55..d81b32b9838 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -174,8 +174,14 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, 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) { + /* if we already got an undersized frame, that must have been the last */ + if (avctx->internal->last_audio_frame) { + av_log(avctx, AV_LOG_ERROR, "frame_size (%d) was not respected for a non-last frame (avcodec_encode_audio2)\n", avctx->frame_size); + ret = AVERROR(EINVAL); + goto end; + } + + if (frame->nb_samples < avctx->frame_size) { ret = pad_last_frame(avctx, &padded_frame, frame); if (ret < 0) goto end; @@ -234,8 +240,8 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, if (ret >= 0) avpkt->data = avpkt->buf->data; } - - avctx->frame_number++; + if (frame) + avctx->frame_number++; } if (ret < 0 || !*got_packet_ptr) { @@ -329,7 +335,8 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx, avpkt->data = avpkt->buf->data; } - avctx->frame_number++; + if (frame) + avctx->frame_number++; } if (ret < 0 || !*got_packet_ptr)