This allows using smaller buffers
Unified · Split
| @@ -1143,8 +1143,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 1142 unmodified lines | ||
| 1143 | 1143 | uint8_t keystate = 128; |
| 1144 | 1144 | uint8_t *buf_p; |
| 1145 | 1145 | int i, ret; |
| 1146 | − int64_t maxsize = FF_INPUT_BUFFER_MIN_SIZE | |
| 1147 | − + avctx->width*avctx->height*37LL*4; | |
| 1146 | + int64_t maxsize; | |
| 1148 | 1147 | |
| 1149 | 1148 | if(!pict) { |
| 1150 | 1149 | if (avctx->flags & AV_CODEC_FLAG_PASS1) { |
| @@ -1192,8 +1191,18 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 41 unmodified lines | ||
| 1192 | 1191 | return 0; |
| 1193 | 1192 | } |
| 1194 | 1193 | |
| 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; | |
| 1197 | 1206 | |
| 1198 | 1207 | if (maxsize > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE - 32) { |
| 1199 | 1208 | av_log(avctx, AV_LOG_WARNING, "Cannot allocate worst case packet size, the encoding could fail\n"); |