[FFmpeg-cvslog] vfilter/vf_qp: Support evaluating expression per MB

Michael Niedermayer git at videolan.org
Sat Mar 28 15:45:50 CET 2015


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sat Mar 28 15:18:58 2015 +0100| [2856634c67985cb623e12299cb8f2c538dd81b17] | committer: Michael Niedermayer

vfilter/vf_qp: Support evaluating expression per MB

also add support for x/y/w/h parameters

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

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

 libavfilter/vf_qp.c |   30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/libavfilter/vf_qp.c b/libavfilter/vf_qp.c
index 8aa670b..0c805af 100644
--- a/libavfilter/vf_qp.c
+++ b/libavfilter/vf_qp.c
@@ -33,6 +33,7 @@ typedef struct QPContext {
     char *qp_expr_str;
     int8_t lut[257];
     int h, qstride;
+    int evaluate_per_mb;
 } QPContext;
 
 #define OFFSET(x) offsetof(QPContext, x)
@@ -52,7 +53,7 @@ static int config_input(AVFilterLink *inlink)
     int i;
     int ret;
     AVExpr *e = NULL;
-    static const char *var_names[] = { "known", "qp", NULL };
+    static const char *var_names[] = { "known", "qp", "x", "y", "w", "h", NULL };
 
     if (!s->qp_expr_str)
         return 0;
@@ -64,12 +65,16 @@ static int config_input(AVFilterLink *inlink)
     s->h       = (inlink->h + 15) >> 4;
     s->qstride = (inlink->w + 15) >> 4;
     for (i = -129; i < 128; i++) {
-        double var_values[] = { i != -129, i, 0};
+        double var_values[] = { i != -129, i, NAN, NAN, s->qstride, s->h, 0};
         double temp_val = av_expr_eval(e, var_values, NULL);
 
         if (isnan(temp_val)) {
+            if(strchr(s->qp_expr_str, 'x') || strchr(s->qp_expr_str, 'y'))
+                s->evaluate_per_mb = 1;
+            else {
                 av_expr_free(e);
                 return AVERROR(EINVAL);
+            }
         }
 
         s->lut[i + 129] = lrintf(temp_val);
@@ -108,7 +113,26 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     in_qp_table = av_frame_get_qp_table(in, &stride, &type);
     av_frame_set_qp_table(out, out_qp_table_buf, s->qstride, type);
 
-    if (in_qp_table) {
+
+    if (s->evaluate_per_mb) {
+        int y, x;
+
+        for (y = 0; y < s->h; y++)
+            for (x = 0; x < s->qstride; x++) {
+                int qp = in_qp_table ? in_qp_table[x + stride * y] : NAN;
+                double var_values[] = { !!in_qp_table, qp, x, y, s->qstride, s->h, 0};
+                static const char *var_names[] = { "known", "qp", "x", "y", "w", "h", NULL };
+                double temp_val;
+                int ret;
+
+                ret = av_expr_parse_and_eval(&temp_val, s->qp_expr_str,
+                                            var_names, var_values,
+                                            NULL, NULL, NULL, NULL, 0, 0, ctx);
+                if (ret < 0)
+                    return ret;
+                out_qp_table_buf->data[x + s->qstride * y] = lrintf(temp_val);
+            }
+    } else if (in_qp_table) {
         int y, x;
 
         for (y = 0; y < s->h; y++)



More information about the ffmpeg-cvslog mailing list