Browse code

Add mode to yadif to enable/disable deinterlacing based on src frame "interlaced" flag

Signed-off-by: Joakim Plate <elupus@ecce.se>

Joakim Plate authored on 2011/07/03 20:19:44
Showing 2 changed files
... ...
@@ -1737,7 +1737,7 @@ Flip the input video vertically.
1737 1737
 Deinterlace the input video ("yadif" means "yet another deinterlacing
1738 1738
 filter").
1739 1739
 
1740
-It accepts the optional parameters: @var{mode}:@var{parity}.
1740
+It accepts the optional parameters: @var{mode}:@var{parity}:@var(auto).
1741 1741
 
1742 1742
 @var{mode} specifies the interlacing mode to adopt, accepts one of the
1743 1743
 following values:
... ...
@@ -1771,6 +1771,18 @@ Default value is -1.
1771 1771
 If interlacing is unknown or decoder does not export this information,
1772 1772
 top field first will be assumed.
1773 1773
 
1774
+@var{auto] specifies if deinterlacer should trust the interlaced flag
1775
+and only deinterlace frames marked as interlaced
1776
+
1777
+@table @option
1778
+@item 0
1779
+deinterlace all frames
1780
+@item 1
1781
+only deinterlace frames marked as interlaced
1782
+@end table
1783
+
1784
+Default value is 0.
1785
+
1774 1786
 @c man end VIDEO FILTERS
1775 1787
 
1776 1788
 @chapter Video Sources
... ...
@@ -44,6 +44,12 @@ typedef struct {
44 44
 
45 45
     int frame_pending;
46 46
 
47
+    /**
48
+     *  0: deinterlace all frames
49
+     *  1: only deinterlace frames marked as interlaced
50
+     */
51
+    int auto_enable;
52
+
47 53
     AVFilterBufferRef *cur;
48 54
     AVFilterBufferRef *next;
49 55
     AVFilterBufferRef *prev;
... ...
@@ -240,6 +246,14 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
240 240
     if (!yadif->cur)
241 241
         return;
242 242
 
243
+    if (yadif->auto_enable && !yadif->cur->video->interlaced) {
244
+        yadif->out  = avfilter_ref_buffer(yadif->cur, AV_PERM_READ);
245
+        avfilter_unref_buffer(yadif->prev);
246
+        yadif->prev = NULL;
247
+        avfilter_start_frame(ctx->outputs[0], yadif->out);
248
+        return;
249
+    }
250
+
243 251
     if (!yadif->prev)
244 252
         yadif->prev = avfilter_ref_buffer(yadif->cur, AV_PERM_READ);
245 253
 
... ...
@@ -259,6 +273,12 @@ static void end_frame(AVFilterLink *link)
259 259
     if (!yadif->out)
260 260
         return;
261 261
 
262
+    if (yadif->auto_enable && !yadif->cur->video->interlaced) {
263
+        avfilter_draw_slice(ctx->outputs[0], 0, link->h, 1);
264
+        avfilter_end_frame(ctx->outputs[0]);
265
+        return;
266
+    }
267
+
262 268
     return_frame(ctx, 0);
263 269
 }
264 270
 
... ...
@@ -299,6 +319,9 @@ static int poll_frame(AVFilterLink *link)
299 299
     }
300 300
     assert(yadif->next || !val);
301 301
 
302
+    if (yadif->auto_enable && yadif->next && !yadif->next->video->interlaced)
303
+        return val;
304
+
302 305
     return val * ((yadif->mode&1)+1);
303 306
 }
304 307
 
... ...
@@ -344,9 +367,10 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
344 344
 
345 345
     yadif->mode = 0;
346 346
     yadif->parity = -1;
347
+    yadif->auto_enable = 0;
347 348
     yadif->csp = NULL;
348 349
 
349
-    if (args) sscanf(args, "%d:%d", &yadif->mode, &yadif->parity);
350
+    if (args) sscanf(args, "%d:%d:%d", &yadif->mode, &yadif->parity, &yadif->auto_enable);
350 351
 
351 352
     yadif->filter_line = filter_line_c;
352 353
     if (HAVE_SSSE3 && cpu_flags & AV_CPU_FLAG_SSSE3)
... ...
@@ -356,7 +380,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
356 356
     else if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX)
357 357
         yadif->filter_line = ff_yadif_filter_line_mmx;
358 358
 
359
-    av_log(ctx, AV_LOG_INFO, "mode:%d parity:%d\n", yadif->mode, yadif->parity);
359
+    av_log(ctx, AV_LOG_INFO, "mode:%d parity:%d auto_enable:%d\n", yadif->mode, yadif->parity, yadif->auto_enable);
360 360
 
361 361
     return 0;
362 362
 }