[FFmpeg-cvslog] Factors for scale filter

Lars Kiesow git at videolan.org
Sat Jan 25 17:05:51 CET 2014


ffmpeg | branch: master | Lars Kiesow <lkiesow at uos.de> | Sat Jan 25 14:40:48 2014 +0100| [7fc4c184630043587ace5b44ef70ccf70c7409fe] | committer: Lars Kiesow

Factors for scale filter

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7fc4c184630043587ace5b44ef70ccf70c7409fe
---

 libavfilter/vf_scale.c |   26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index 2e692cf..bda536d 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -270,11 +270,20 @@ static int config_props(AVFilterLink *outlink)
     w = scale->w;
     h = scale->h;
 
-    /* sanity check params */
-    if (w <  -1 || h <  -1) {
-        av_log(ctx, AV_LOG_ERROR, "Size values less than -1 are not acceptable.\n");
-        return AVERROR(EINVAL);
+    /* Check if it is requested that the result has to be divisible by a some
+     * factor (w or h = -n with n being the factor). After we got the factor,
+     * we set w/h back to -1 so that the automatic scaling is done. */
+    int factor_w = 1;
+    int factor_h = 1;
+    if (w < -1) {
+        factor_w = -w;
+        w = -1;
     }
+    if (h < -1) {
+        factor_h = -h;
+        h = -1;
+    }
+
     if (w == -1 && h == -1)
         scale->w = scale->h = 0;
 
@@ -287,6 +296,15 @@ static int config_props(AVFilterLink *outlink)
     if (h == -1)
         h = av_rescale(w, inlink->h, inlink->w);
 
+    /* Make sure that the result is divisible by the factor we determined
+     * earlier. If no factor was set, it is nothing will happen as the default
+     * factor is 1 */
+    w = (w / factor_w) * factor_w;
+    h = (h / factor_h) * factor_h;
+
+
+    /* Note that force_original_aspect_ratio may overwrite the previous set
+     * dimensions so that it is not divisible by the set factors anymore. */
     if (scale->force_original_aspect_ratio) {
         int tmp_w = av_rescale(h, inlink->w, inlink->h);
         int tmp_h = av_rescale(w, inlink->h, inlink->w);



More information about the ffmpeg-cvslog mailing list