[FFmpeg-devel,v2] avfilter/vf_delogo: avfilter/vf_delogo: add auto set the area inside of the frame

Submitted by Steven Liu on Sept. 3, 2019, 11:54 a.m.

Details

Message ID 20190903115426.98164-1-lq@chinaffmpeg.org
State New
Headers show

Commit Message

Steven Liu Sept. 3, 2019, 11:54 a.m.
when the area outside of the frame, then use expr should
give user warning message and auto set to the area inside of the frame.

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
---
 libavfilter/vf_delogo.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Moritz Barsnick Sept. 4, 2019, 12:23 p.m.
On Tue, Sep 03, 2019 at 19:54:26 +0800, Steven Liu wrote:
> +        av_log(s, AV_LOG_WARNING, "Logo area is outside of the frame,"
> +               "auto set the area inside of the frame\n");

Missing a space after the comma inside the message text (lost while
breaking the C string).

Moritz

Patch hide | download patch | download mbox

diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c
index 814575a36c..2d058021fb 100644
--- a/libavfilter/vf_delogo.c
+++ b/libavfilter/vf_delogo.c
@@ -327,6 +327,21 @@  static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     s->w = av_expr_eval(s->w_pexpr, s->var_values, s);
     s->h = av_expr_eval(s->h_pexpr, s->var_values, s);
 
+    if (s->x + (s->band - 1) <= 0 || s->x + s->w - (s->band*2 - 2) > inlink->w ||
+        s->y + (s->band - 1) <= 0 || s->y + s->h - (s->band*2 - 2) > inlink->h) {
+        av_log(s, AV_LOG_WARNING, "Logo area is outside of the frame,"
+               "auto set the area inside of the frame\n");
+    }
+
+    if (s->x + (s->band - 1) <= 0)
+        s->x = 1 + s->band;
+    if (s->y + (s->band - 1) <= 0)
+        s->y = 1 + s->band;
+    if (s->x + s->w - (s->band*2 - 2) > inlink->w)
+        s->w = inlink->w - s->x - (s->band*2 - 2);
+    if (s->y + s->h - (s->band*2 - 2) > inlink->h)
+        s->h = inlink->h - s->y - (s->band*2 - 2);
+
     ret = config_input(inlink);
     if (ret < 0) {
         av_frame_free(&in);