]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/ffv1enc.c
Merge commit 'bfe1cd80ebeab58cbc1c91ac766a96fce8e4ec1e'
[ffmpeg] / libavcodec / ffv1enc.c
index 265ced11724cedc0f0a1867af796328b247d457a..5bd93fb2e9cc29e5e14d2cff3b715416b086bc74 100644 (file)
@@ -683,8 +683,13 @@ static av_cold int encode_init(AVCodecContext *avctx)
     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);
@@ -977,6 +982,7 @@ slices_ok:
 
     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;
 
@@ -986,7 +992,7 @@ slices_ok:
         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] *
@@ -1210,6 +1216,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
             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++) {