if (avctx->level <= 0 && s->version == 2) {
s->version = 3;
}
- if (avctx->level >= 0 && avctx->level <= 4)
- s->version = FFMAX(s->version, avctx->level);
+ if (avctx->level >= 0 && avctx->level <= 4) {
+ if (avctx->level < s->version) {
+ av_log(avctx, AV_LOG_ERROR, "Version %d needed for requested features but %d requested\n", s->version, avctx->level);
+ return AVERROR(EINVAL);
+ }
+ s->version = avctx->level;
+ }
if (s->ec < 0) {
s->ec = (s->version >= 3);
if ((ret = ff_ffv1_init_slice_contexts(s)) < 0)
return ret;
+ s->slice_count = s->max_slice_count;
if ((ret = ff_ffv1_init_slices_state(s)) < 0)
return ret;
if (!avctx->stats_out)
return AVERROR(ENOMEM);
for (i = 0; i < s->quant_table_count; i++)
- for (j = 0; j < s->slice_count; j++) {
+ for (j = 0; j < s->max_slice_count; j++) {
FFV1Context *sf = s->slice_context[j];
av_assert0(!sf->rc_stat2[i]);
sf->rc_stat2[i] = av_mallocz(s->context_count[i] *
for (i = 0; i < f->quant_table_count; i++)
memset(f->rc_stat2[i], 0, f->context_count[i] * sizeof(*f->rc_stat2[i]));
+ av_assert0(f->slice_count == f->max_slice_count);
for (j = 0; j < f->slice_count; j++) {
FFV1Context *fs = f->slice_context[j];
for (i = 0; i < 256; i++) {