X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fencode.c;h=d81b32b98382ee7731d6bb5312464c98a3eef610;hb=5e546864b09379910721b35a14713982d933d9dd;hp=d9761515aa84e2ccdf5040fdabd6fb9af310bc4f;hpb=b14761d1f8372dfe558193b8b754b9f1a858077d;p=ffmpeg diff --git a/libavcodec/encode.c b/libavcodec/encode.c index d9761515aa8..d81b32b9838 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -135,7 +135,6 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY) && !frame) { av_packet_unref(avpkt); - av_init_packet(avpkt); return 0; } @@ -175,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; @@ -235,13 +240,12 @@ 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) { av_packet_unref(avpkt); - av_init_packet(avpkt); goto end; } @@ -282,8 +286,6 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx, if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY) && !frame) { av_packet_unref(avpkt); - av_init_packet(avpkt); - avpkt->size = 0; return 0; } @@ -333,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)