Commit 2856634c authored by Michael Niedermayer's avatar Michael Niedermayer

vfilter/vf_qp: Support evaluating expression per MB

also add support for x/y/w/h parameters
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent a8fb8f61
...@@ -33,6 +33,7 @@ typedef struct QPContext { ...@@ -33,6 +33,7 @@ typedef struct QPContext {
char *qp_expr_str; char *qp_expr_str;
int8_t lut[257]; int8_t lut[257];
int h, qstride; int h, qstride;
int evaluate_per_mb;
} QPContext; } QPContext;
#define OFFSET(x) offsetof(QPContext, x) #define OFFSET(x) offsetof(QPContext, x)
...@@ -52,7 +53,7 @@ static int config_input(AVFilterLink *inlink) ...@@ -52,7 +53,7 @@ static int config_input(AVFilterLink *inlink)
int i; int i;
int ret; int ret;
AVExpr *e = NULL; 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) if (!s->qp_expr_str)
return 0; return 0;
...@@ -64,12 +65,16 @@ static int config_input(AVFilterLink *inlink) ...@@ -64,12 +65,16 @@ static int config_input(AVFilterLink *inlink)
s->h = (inlink->h + 15) >> 4; s->h = (inlink->h + 15) >> 4;
s->qstride = (inlink->w + 15) >> 4; s->qstride = (inlink->w + 15) >> 4;
for (i = -129; i < 128; i++) { 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); double temp_val = av_expr_eval(e, var_values, NULL);
if (isnan(temp_val)) { 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); av_expr_free(e);
return AVERROR(EINVAL); return AVERROR(EINVAL);
}
} }
s->lut[i + 129] = lrintf(temp_val); s->lut[i + 129] = lrintf(temp_val);
...@@ -108,7 +113,26 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) ...@@ -108,7 +113,26 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
in_qp_table = av_frame_get_qp_table(in, &stride, &type); in_qp_table = av_frame_get_qp_table(in, &stride, &type);
av_frame_set_qp_table(out, out_qp_table_buf, s->qstride, 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; int y, x;
for (y = 0; y < s->h; y++) for (y = 0; y < s->h; y++)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment