History

avcodec/ffv1enc: Tighter maxsize

This allows using smaller buffers

Michael Niedermayer committed 2 years ago

Commit ebffb8b1 parent 2d81eaa1 file · +13 −4Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/ffv1enc.c+13−4
@@ -1143,8 +1143,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 1142 unmodified lines
1143 uint8_t keystate = 128;1143 uint8_t keystate = 128;
1144 uint8_t *buf_p;1144 uint8_t *buf_p;
1145 int i, ret;1145 int i, ret;
1146 int64_t maxsize = FF_INPUT_BUFFER_MIN_SIZE1146 int64_t maxsize;
1147 + avctx->width*avctx->height*37LL*4;
1148 1147
1149 if(!pict) {1148 if(!pict) {
1150 if (avctx->flags & AV_CODEC_FLAG_PASS1) {1149 if (avctx->flags & AV_CODEC_FLAG_PASS1) {
@@ -1192,8 +1191,18 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 41 unmodified lines
1192 return 0;1191 return 0;
1193 }1192 }
1194 1193
1195 if (f->version > 3)1194 maxsize = avctx->width*avctx->height * (1 + f->transparency);
1196 maxsize = FF_INPUT_BUFFER_MIN_SIZE + avctx->width*avctx->height*3LL*4;1195 if (f->chroma_planes)
1196 maxsize += AV_CEIL_RSHIFT(avctx->width, f->chroma_h_shift) * AV_CEIL_RSHIFT(f->height, f->chroma_v_shift) * 2;
1197 maxsize += f->slice_count * 800; //for slice header
1198 if (f->version > 3) {
1199 maxsize *= f->bits_per_raw_sample + 1;
1200 } else {
1201 maxsize += f->slice_count * 2 * (avctx->width + avctx->height); //for bug with slices that code some pixels more than once
1202 maxsize *= 8*(2*f->bits_per_raw_sample + 5);
1203 }
1204 maxsize >>= 3;
1205 maxsize += FF_INPUT_BUFFER_MIN_SIZE;
1197 1206
1198 if (maxsize > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE - 32) {1207 if (maxsize > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE - 32) {
1199 av_log(avctx, AV_LOG_WARNING, "Cannot allocate worst case packet size, the encoding could fail\n");1208 av_log(avctx, AV_LOG_WARNING, "Cannot allocate worst case packet size, the encoding could fail\n");

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