diff mbox

[FFmpeg-devel] libavfilter/vf_delogo: add options start and stop frame number

Message ID 20180217125309.3968-1-qq2225936589@163.com
State New
Headers show

Commit Message

qq2225936589 Feb. 17, 2018, 12:53 p.m. UTC
From: qq2225936589 <qq2225936589@gmail.com>

---
 libavfilter/vf_delogo.c | 52 +++++++++++++++++++++++++++++--------------------
 1 file changed, 31 insertions(+), 21 deletions(-)

Comments

Gyan Feb. 17, 2018, 6:17 p.m. UTC | #1
On 2/17/2018 6:23 PM, qq2225936589 wrote:
> +    { "f1",   "set delogo start frame number",OFFSET(f1),    AV_OPT_TYPE_INT, { .i64 = 0 },   0, INT_MAX, FLAGS },
> +    { "f2",   "set delogo stop frame number", OFFSET(f2),    AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },

This filter has timeline support - doesn't that work?

Regards,
Gyan
diff mbox

Patch

diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c
index 065d093641..f568b4eb7e 100644
--- a/libavfilter/vf_delogo.c
+++ b/libavfilter/vf_delogo.c
@@ -155,7 +155,7 @@  static void apply_delogo(uint8_t *dst, int dst_linesize,
 
 typedef struct DelogoContext {
     const AVClass *class;
-    int x, y, w, h, band, show;
+    int x, y, w, h, band, show, f1, f2;
 }  DelogoContext;
 
 #define OFFSET(x) offsetof(DelogoContext, x)
@@ -172,6 +172,8 @@  static const AVOption delogo_options[]= {
     { "t",    "set delogo area band size", OFFSET(band), AV_OPT_TYPE_INT, { .i64 =  0 },  0, INT_MAX, FLAGS },
 #endif
     { "show", "show delogo area",          OFFSET(show), AV_OPT_TYPE_BOOL,{ .i64 =  0 },  0, 1,       FLAGS },
+    { "f1",   "set delogo start frame number",OFFSET(f1),    AV_OPT_TYPE_INT, { .i64 = 0 },   0, INT_MAX, FLAGS },
+    { "f2",   "set delogo stop frame number", OFFSET(f2),    AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
     { NULL }
 };
 
@@ -195,10 +197,10 @@  static av_cold int init(AVFilterContext *ctx)
 {
     DelogoContext *s = ctx->priv;
 
-#define CHECK_UNSET_OPT(opt)                                            \
+#define CHECK_UNSET_OPT(opt)                                       \
     if (s->opt == -1) {                                            \
         av_log(s, AV_LOG_ERROR, "Option %s was not set.\n", #opt); \
-        return AVERROR(EINVAL);                                         \
+        return AVERROR(EINVAL);                                    \
     }
     CHECK_UNSET_OPT(x);
     CHECK_UNSET_OPT(y);
@@ -215,8 +217,8 @@  static av_cold int init(AVFilterContext *ctx)
 #else
     s->band = 1;
 #endif
-    av_log(ctx, AV_LOG_VERBOSE, "x:%d y:%d, w:%d h:%d band:%d show:%d\n",
-           s->x, s->y, s->w, s->h, s->band, s->show);
+    av_log(ctx, AV_LOG_VERBOSE, "x:%d y:%d, w:%d h:%d band:%d show:%d f1:%d f2:%d\n",
+           s->x, s->y, s->w, s->h, s->band, s->show, s->f1, s->f2);
 
     s->w += s->band*2;
     s->h += s->band*2;
@@ -252,6 +254,9 @@  static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     int plane;
     AVRational sar;
 
+    int64_t frame_num = inlink->frame_count_out;
+    av_log(s, AV_LOG_VERBOSE, "frame:%"PRId64" f1:%d f2:%d\n", frame_num, s->f1, s->f2);
+
     if (av_frame_is_writable(in)) {
         direct = 1;
         out = in;
@@ -269,22 +274,27 @@  static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     /* Assume square pixels if SAR is unknown */
     if (!sar.num)
         sar.num = sar.den = 1;
-
-    for (plane = 0; plane < desc->nb_components; plane++) {
-        int hsub = plane == 1 || plane == 2 ? hsub0 : 0;
-        int vsub = plane == 1 || plane == 2 ? vsub0 : 0;
-
-        apply_delogo(out->data[plane], out->linesize[plane],
-                     in ->data[plane], in ->linesize[plane],
-                     AV_CEIL_RSHIFT(inlink->w, hsub),
-                     AV_CEIL_RSHIFT(inlink->h, vsub),
-                     sar, s->x>>hsub, s->y>>vsub,
-                     /* Up and left borders were rounded down, inject lost bits
-                      * into width and height to avoid error accumulation */
-                     AV_CEIL_RSHIFT(s->w + (s->x & ((1<<hsub)-1)), hsub),
-                     AV_CEIL_RSHIFT(s->h + (s->y & ((1<<vsub)-1)), vsub),
-                     s->band>>FFMIN(hsub, vsub),
-                     s->show, direct);
+    if( ( s->f1 == 0 && s->f2 == -1) ||
+        ( frame_num >= s->f1 && frame_num <= s->f2) ) {
+        for (plane = 0; plane < desc->nb_components; plane++) {
+            int hsub = plane == 1 || plane == 2 ? hsub0 : 0;
+            int vsub = plane == 1 || plane == 2 ? vsub0 : 0;
+
+            apply_delogo(out->data[plane], out->linesize[plane],
+                         in ->data[plane], in ->linesize[plane],
+                         AV_CEIL_RSHIFT(inlink->w, hsub),
+                         AV_CEIL_RSHIFT(inlink->h, vsub),
+                         sar, s->x>>hsub, s->y>>vsub,
+                         /* Up and left borders were rounded down, inject lost bits
+                          * into width and height to avoid error accumulation */
+                         AV_CEIL_RSHIFT(s->w + (s->x & ((1<<hsub)-1)), hsub),
+                         AV_CEIL_RSHIFT(s->h + (s->y & ((1<<vsub)-1)), vsub),
+                         s->band>>FFMIN(hsub, vsub),
+                         s->show, direct);
+        }
+    } else {
+        av_frame_copy_props(out, in);
+        av_frame_copy(out, in);
     }
 
     if (!direct)