Browse code

avcodec/ffv1enc: compute the max number of slices and limit by that

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>

Michael Niedermayer authored on 2017/06/27 20:09:58
Showing 1 changed files
... ...
@@ -849,16 +849,17 @@ FF_ENABLE_DEPRECATION_WARNINGS
849 849
 
850 850
     if (s->version > 1) {
851 851
         int plane_count = 1 + 2*s->chroma_planes + s->transparency;
852
+        int max_h_slices = AV_CEIL_RSHIFT(avctx->width , s->chroma_h_shift);
853
+        int max_v_slices = AV_CEIL_RSHIFT(avctx->height, s->chroma_v_shift);
852 854
         s->num_v_slices = (avctx->width > 352 || avctx->height > 288 || !avctx->slices) ? 2 : 1;
853 855
 
854
-        if (avctx->height < 5)
855
-            s->num_v_slices = 1;
856
+        s->num_v_slices = FFMIN(s->num_v_slices, max_v_slices);
856 857
 
857 858
         for (; s->num_v_slices < 32; s->num_v_slices++) {
858 859
             for (s->num_h_slices = s->num_v_slices; s->num_h_slices < 2*s->num_v_slices; s->num_h_slices++) {
859 860
                 int maxw = (avctx->width  + s->num_h_slices - 1) / s->num_h_slices;
860 861
                 int maxh = (avctx->height + s->num_v_slices - 1) / s->num_v_slices;
861
-                if (s->num_h_slices > avctx->width || s->num_v_slices > avctx->height)
862
+                if (s->num_h_slices > max_h_slices || s->num_v_slices > max_v_slices)
862 863
                     continue;
863 864
                 if (maxw * maxh * (int64_t)(s->bits_per_raw_sample+1) * plane_count > 8<<24)
864 865
                     continue;