[FFmpeg-devel] lavfi: remove the duplicate expression evaluation.

Submitted by Jun Zhao on Jan. 9, 2017, 12:12 a.m.

Details

Message ID 3cc5e343-fdd9-0ff4-3df2-dcdcad039750@gmail.com
State New
Headers show

Commit Message

Jun Zhao Jan. 9, 2017, 12:12 a.m.
From 80ea322e8bd634dbf93291f7a4d78bc87834c0a8 Mon Sep 17 00:00:00 2001
From: Jun Zhao <mypopydev@gmail.com>
Date: Sun, 8 Jan 2017 14:26:39 +0800
Subject: [PATCH] lavfi: remove the duplicate expression evaluation.

remove the duplicate expression evaluation in crop/drawtext/overlay.

Signed-off-by: Jun Zhao <jun.zhao@intel.com>
---
 libavfilter/vf_crop.c     | 1 -
 libavfilter/vf_drawtext.c | 1 -
 libavfilter/vf_overlay.c  | 1 -
 3 files changed, 3 deletions(-)

Comments

Mark Thompson Jan. 9, 2017, 12:21 a.m.
On 09/01/17 00:12, Jun Zhao wrote:
> From 80ea322e8bd634dbf93291f7a4d78bc87834c0a8 Mon Sep 17 00:00:00 2001
> From: Jun Zhao <mypopydev@gmail.com>
> Date: Sun, 8 Jan 2017 14:26:39 +0800
> Subject: [PATCH] lavfi: remove the duplicate expression evaluation.
> 
> remove the duplicate expression evaluation in crop/drawtext/overlay.
> 
> Signed-off-by: Jun Zhao <jun.zhao@intel.com>
> ---
>  libavfilter/vf_crop.c     | 1 -
>  libavfilter/vf_drawtext.c | 1 -
>  libavfilter/vf_overlay.c  | 1 -
>  3 files changed, 3 deletions(-)
> 
> diff --git a/libavfilter/vf_crop.c b/libavfilter/vf_crop.c
> index 85ea892..4a032d1 100644
> --- a/libavfilter/vf_crop.c
> +++ b/libavfilter/vf_crop.c
> @@ -262,7 +262,6 @@ static int filter_frame(AVFilterLink *link, AVFrame *frame)
>          NAN : av_frame_get_pkt_pos(frame);
>      s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, NULL);
>      s->var_values[VAR_Y] = av_expr_eval(s->y_pexpr, s->var_values, NULL);
> -    s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, NULL);
>  
>      normalize_double(&s->x, s->var_values[VAR_X]);
>      normalize_double(&s->y, s->var_values[VAR_Y]);
> diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
> index 649240b..a485362 100644
> --- a/libavfilter/vf_drawtext.c
> +++ b/libavfilter/vf_drawtext.c
> @@ -1288,7 +1288,6 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame,
>  
>      s->x = s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, &s->prng);
>      s->y = s->var_values[VAR_Y] = av_expr_eval(s->y_pexpr, s->var_values, &s->prng);
> -    s->x = s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, &s->prng);
>  
>      update_alpha(s);
>      update_color_with_alpha(s, &fontcolor  , s->fontcolor  );
> diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c
> index 108a6fc..ea5889e 100644
> --- a/libavfilter/vf_overlay.c
> +++ b/libavfilter/vf_overlay.c
> @@ -159,7 +159,6 @@ static void eval_expr(AVFilterContext *ctx)
>  
>      s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, NULL);
>      s->var_values[VAR_Y] = av_expr_eval(s->y_pexpr, s->var_values, NULL);
> -    s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, NULL);
>      s->x = normalize_xy(s->var_values[VAR_X], s->hsub);
>      s->y = normalize_xy(s->var_values[VAR_Y], s->vsub);
>  }
> -- 
> 2.1.4

Isn't the point of this that you can have an expression for x which depends on y, or an expression for y which depends on x, working either way around?

- Mark
Jun Zhao Jan. 9, 2017, 12:53 a.m.
On 2017/1/9 8:21, Mark Thompson wrote:
> On 09/01/17 00:12, Jun Zhao wrote:
>> From 80ea322e8bd634dbf93291f7a4d78bc87834c0a8 Mon Sep 17 00:00:00 2001
>> From: Jun Zhao <mypopydev@gmail.com>
>> Date: Sun, 8 Jan 2017 14:26:39 +0800
>> Subject: [PATCH] lavfi: remove the duplicate expression evaluation.
>>
>> remove the duplicate expression evaluation in crop/drawtext/overlay.
>>
>> Signed-off-by: Jun Zhao <jun.zhao@intel.com>
>> ---
>>  libavfilter/vf_crop.c     | 1 -
>>  libavfilter/vf_drawtext.c | 1 -
>>  libavfilter/vf_overlay.c  | 1 -
>>  3 files changed, 3 deletions(-)
>>
>> diff --git a/libavfilter/vf_crop.c b/libavfilter/vf_crop.c
>> index 85ea892..4a032d1 100644
>> --- a/libavfilter/vf_crop.c
>> +++ b/libavfilter/vf_crop.c
>> @@ -262,7 +262,6 @@ static int filter_frame(AVFilterLink *link, AVFrame *frame)
>>          NAN : av_frame_get_pkt_pos(frame);
>>      s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, NULL);
>>      s->var_values[VAR_Y] = av_expr_eval(s->y_pexpr, s->var_values, NULL);
>> -    s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, NULL);
>>  
>>      normalize_double(&s->x, s->var_values[VAR_X]);
>>      normalize_double(&s->y, s->var_values[VAR_Y]);
>> diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
>> index 649240b..a485362 100644
>> --- a/libavfilter/vf_drawtext.c
>> +++ b/libavfilter/vf_drawtext.c
>> @@ -1288,7 +1288,6 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame,
>>  
>>      s->x = s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, &s->prng);
>>      s->y = s->var_values[VAR_Y] = av_expr_eval(s->y_pexpr, s->var_values, &s->prng);
>> -    s->x = s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, &s->prng);
>>  
>>      update_alpha(s);
>>      update_color_with_alpha(s, &fontcolor  , s->fontcolor  );
>> diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c
>> index 108a6fc..ea5889e 100644
>> --- a/libavfilter/vf_overlay.c
>> +++ b/libavfilter/vf_overlay.c
>> @@ -159,7 +159,6 @@ static void eval_expr(AVFilterContext *ctx)
>>  
>>      s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, NULL);
>>      s->var_values[VAR_Y] = av_expr_eval(s->y_pexpr, s->var_values, NULL);
>> -    s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, NULL);
>>      s->x = normalize_xy(s->var_values[VAR_X], s->hsub);
>>      s->y = normalize_xy(s->var_values[VAR_Y], s->vsub);
>>  }
>> -- 
>> 2.1.4
> 
> Isn't the point of this that you can have an expression for x which depends on y, or an expression for y which depends on x, working either way around?
> 
> - Mark

I didn't find any case about x depends on y or y depends y.

If have this dependency relationship , why the code don't handle out_w/out_h in 
crop?

> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
Nicolas George Jan. 9, 2017, 10:46 a.m.
Le decadi 20 nivôse, an CCXXV, Jun Zhao a écrit :
> I didn't find any case about x depends on y or y depends y.

Some users have occasionally asked for it, IIRC.

> If have this dependency relationship , why the code don't handle out_w/out_h in 
> crop?

Ideally, all variables should be able to be expressed based on any
other, and the system should find an order of evaluation that works.
Alas, this is rather complex to implement.

Regards,
wm4 Jan. 9, 2017, 11:02 a.m.
On Mon, 9 Jan 2017 11:46:01 +0100
Nicolas George <george@nsup.org> wrote:

> Le decadi 20 nivôse, an CCXXV, Jun Zhao a écrit :
> > I didn't find any case about x depends on y or y depends y.  
> 
> Some users have occasionally asked for it, IIRC.
> 
> > If have this dependency relationship , why the code don't handle out_w/out_h in 
> > crop?  
> 
> Ideally, all variables should be able to be expressed based on any
> other, and the system should find an order of evaluation that works.
> Alas, this is rather complex to implement.

A start would be not having to do this in every filter ever.

Other filter systems (such as vapoursynth) do not even make the mistake
of conflating user language and underlying mechanisms.

Patch hide | download patch | download mbox

diff --git a/libavfilter/vf_crop.c b/libavfilter/vf_crop.c
index 85ea892..4a032d1 100644
--- a/libavfilter/vf_crop.c
+++ b/libavfilter/vf_crop.c
@@ -262,7 +262,6 @@  static int filter_frame(AVFilterLink *link, AVFrame *frame)
         NAN : av_frame_get_pkt_pos(frame);
     s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, NULL);
     s->var_values[VAR_Y] = av_expr_eval(s->y_pexpr, s->var_values, NULL);
-    s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, NULL);
 
     normalize_double(&s->x, s->var_values[VAR_X]);
     normalize_double(&s->y, s->var_values[VAR_Y]);
diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index 649240b..a485362 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -1288,7 +1288,6 @@  static int draw_text(AVFilterContext *ctx, AVFrame *frame,
 
     s->x = s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, &s->prng);
     s->y = s->var_values[VAR_Y] = av_expr_eval(s->y_pexpr, s->var_values, &s->prng);
-    s->x = s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, &s->prng);
 
     update_alpha(s);
     update_color_with_alpha(s, &fontcolor  , s->fontcolor  );
diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c
index 108a6fc..ea5889e 100644
--- a/libavfilter/vf_overlay.c
+++ b/libavfilter/vf_overlay.c
@@ -159,7 +159,6 @@  static void eval_expr(AVFilterContext *ctx)
 
     s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, NULL);
     s->var_values[VAR_Y] = av_expr_eval(s->y_pexpr, s->var_values, NULL);
-    s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, NULL);
     s->x = normalize_xy(s->var_values[VAR_X], s->hsub);
     s->y = normalize_xy(s->var_values[VAR_Y], s->vsub);
 }