[FFmpeg-devel] [PATCH 23/24] lavfi/vf_scale: forward errors from swscale

Anton Khirnov anton at khirnov.net
Mon May 31 10:55:14 EEST 2021


---
 libavfilter/vf_scale.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index 37899de6a1..cdd7c4da0d 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -658,6 +658,7 @@ static int scale_frame(AVFilterLink *link, AVFrame *in, AVFrame **frame_out)
     AVFrame *out;
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format);
     char buf[32];
+    int ret;
     int in_range;
     int frame_changed;
 
@@ -672,7 +673,6 @@ static int scale_frame(AVFilterLink *link, AVFrame *in, AVFrame **frame_out)
                     in->sample_aspect_ratio.num != link->sample_aspect_ratio.num;
 
     if (scale->eval_mode == EVAL_MODE_FRAME || frame_changed) {
-        int ret;
         unsigned vars_w[VARS_NB] = { 0 }, vars_h[VARS_NB] = { 0 };
 
         av_expr_count_vars(scale->w_pexpr, vars_w, VARS_NB);
@@ -794,8 +794,9 @@ scale:
               INT_MAX);
 
     if (scale->interlaced>0 || (scale->interlaced<0 && in->interlaced_frame)) {
-        scale_slice(scale, out, in, scale->isws[0], 0, (link->h+1)/2, 2, 0);
-        scale_slice(scale, out, in, scale->isws[1], 0,  link->h   /2, 2, 1);
+        ret = scale_slice(scale, out, in, scale->isws[0], 0, (link->h+1)/2, 2, 0);
+        if (ret >= 0)
+            ret = scale_slice(scale, out, in, scale->isws[1], 0,  link->h   /2, 2, 1);
     } else if (scale->nb_slices) {
         int i, slice_h, slice_start, slice_end = 0;
         const int nb_slices = FFMIN(scale->nb_slices, link->h);
@@ -803,14 +804,18 @@ scale:
             slice_start = slice_end;
             slice_end   = (link->h * (i+1)) / nb_slices;
             slice_h     = slice_end - slice_start;
-            scale_slice(scale, out, in, scale->sws, slice_start, slice_h, 1, 0);
+            ret = scale_slice(scale, out, in, scale->sws, slice_start, slice_h, 1, 0);
+            if (ret < 0)
+                break;
         }
     } else {
-        scale_slice(scale, out, in, scale->sws, 0, link->h, 1, 0);
+        ret = scale_slice(scale, out, in, scale->sws, 0, link->h, 1, 0);
     }
 
     av_frame_free(&in);
-    return 0;
+    if (ret < 0)
+        av_frame_free(frame_out);
+    return ret;
 }
 
 static int filter_frame(AVFilterLink *link, AVFrame *in)
-- 
2.30.2



More information about the ffmpeg-devel mailing list