diff options
author | Nicolas George <nicolas.george@normalesup.org> | 2012-02-29 14:39:50 +0100 |
---|---|---|
committer | Nicolas George <nicolas.george@normalesup.org> | 2012-02-29 17:00:26 +0100 |
commit | 33b9fe562a307629d8db61edcf729c4cb8f78413 (patch) | |
tree | 12fa88a07df66e9bda12b57ec61fe157128b384f | |
parent | 52ae41a87472c040aa79edf231a9bff2f3376869 (diff) | |
download | ffmpeg-33b9fe562a307629d8db61edcf729c4cb8f78413.tar.gz |
encode_video2: shrink packet after encoding.
With the encode2 API, encoders allocate huge packets to be
sure they have enough room (a typical case is mpeg4, which
allocs ~10M for 1280x768 yuv420p) but only actually use a
very small part of the buffer.
-rw-r--r-- | libavcodec/utils.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 63f7fae88a..99e36f84a8 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -1198,6 +1198,7 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx, { int ret; int user_packet = !!avpkt->data; + void *new_data; *got_packet_ptr = 0; @@ -1218,6 +1219,12 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx, avpkt->size = 0; else if (!(avctx->codec->capabilities & CODEC_CAP_DELAY)) avpkt->pts = avpkt->dts = frame->pts; + if (avpkt->data) { + new_data = av_realloc(avpkt->data, + avpkt->size + FF_INPUT_BUFFER_PADDING_SIZE); + if (new_data) + avpkt->data = new_data; + } avctx->frame_number++; } |