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
11431143 uint8_t keystate = 128;
11441144 uint8_t *buf_p;
11451145 int i, ret;
1146− int64_t maxsize = FF_INPUT_BUFFER_MIN_SIZE
1147− + avctx->width*avctx->height*37LL*4;
1146+ int64_t maxsize;
11481147
11491148 if(!pict) {
11501149 if (avctx->flags & AV_CODEC_FLAG_PASS1) {
@@ -1192,8 +1191,18 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 41 unmodified lines
11921191 return 0;
11931192 }
11941193
1195− if (f->version > 3)
1196− maxsize = FF_INPUT_BUFFER_MIN_SIZE + avctx->width*avctx->height*3LL*4;
1194+ maxsize = avctx->width*avctx->height * (1 + f->transparency);
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;
11971206
11981207 if (maxsize > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE - 32) {
11991208 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