History

avcodec/mpegvideo_enc: Fix unnecessary linear growth of buffer

If one encodes MJPEG with a single slice and uses input with AV_FRAME_DATA_ICC_PROFILE side data, the current allocation code in ff_mpv_encode_picture() will always increase the size of the temporary buffer used for allocating packets by the size needed for to write the ICC chunk even when the current buffer is actually large enough. This commit fixes this.

Andreas Rheinhardt committed 4 years ago

Commit c3047da1 parent 4487dd81 file · +3 −3Browse files

Unified · Split

libavcodec/mpegvideo_enc.c+3−3
@@ -1684,9 +1684,8 @@ int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, · 1683 unmodified lines
1684 /* output? */1684 /* output? */
1685 if (s->new_picture->data[0]) {1685 if (s->new_picture->data[0]) {
1686 int growing_buffer = context_count == 1 && !pkt->data && !s->data_partitioning;1686 int growing_buffer = context_count == 1 && !pkt->data && !s->data_partitioning;
1687 size_t pkt_size = growing_buffer ? FFMAX(s->mb_width*s->mb_height*64+10000, avctx->internal->byte_buffer_size) - AV_INPUT_BUFFER_PADDING_SIZE1687 size_t pkt_size = 10000 + s->mb_width * s->mb_height *
1688 :1688 (growing_buffer ? 64 : (MAX_MB_BYTES + 100));
1689 s->mb_width*s->mb_height*(MAX_MB_BYTES+100)+10000;
1690 if (CONFIG_MJPEG_ENCODER && avctx->codec_id == AV_CODEC_ID_MJPEG) {1689 if (CONFIG_MJPEG_ENCODER && avctx->codec_id == AV_CODEC_ID_MJPEG) {
1691 ret = ff_mjpeg_add_icc_profile_size(avctx, s->new_picture, &pkt_size);1690 ret = ff_mjpeg_add_icc_profile_size(avctx, s->new_picture, &pkt_size);
1692 if (ret < 0)1691 if (ret < 0)
@@ -1694,6 +1693,7 @@ int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, · 1 unmodified line
1694 }1693 }
1695 if ((ret = ff_alloc_packet(avctx, pkt, pkt_size)) < 0)1694 if ((ret = ff_alloc_packet(avctx, pkt, pkt_size)) < 0)
1696 return ret;1695 return ret;
1696 pkt->size = avctx->internal->byte_buffer_size - AV_INPUT_BUFFER_PADDING_SIZE;
1697 if (s->mb_info) {1697 if (s->mb_info) {
1698 s->mb_info_ptr = av_packet_new_side_data(pkt,1698 s->mb_info_ptr = av_packet_new_side_data(pkt,
1699 AV_PKT_DATA_H263_MB_INFO,1699 AV_PKT_DATA_H263_MB_INFO,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t