From b32ecf9a8947ba2d9f6861a186893609c05afa82 Mon Sep 17 00:00:00 2001
From: dsmudhar <ds.mudhar@gmail.com>
Date: Sun, 8 May 2016 01:14:44 +0530
Subject: [PATCH 2/2] vf_codecview: added i-frame support

---
 doc/filters.texi           | 10 ++++++----
 libavfilter/vf_codecview.c | 12 ++++++++----
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 71a4ac4..e084094 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -4727,10 +4727,12 @@ Set frame types to display motion vectors of.
 Available flags for @var{frames} are:
 
 @table @samp
+@item if
+intra-coded frames (I-frames)
 @item pf
-predicted frames (p-frames)
+predicted frames (P-frames)
 @item bf
-bi-directionally predicted frames (b-frames)
+bi-directionally predicted frames (B-frames)
 @end table
 
 @item qp
@@ -4741,13 +4743,13 @@ Display quantization parameters using the chroma planes
 
 @itemize
 @item
-Visualizes forward predicted MVs from all frames using @command{ffplay}:
+Visualize forward predicted MVs from all frames using @command{ffplay}:
 @example
 ffplay -flags2 +export_mvs input.mpg -vf codecview=mv=fp
 @end example
 
 @item
-Visualizes multi-directionals MVs from P and B-Frames:
+Visualize multi-directional MVs from P and B-frames:
 @example
 ffplay -flags2 +export_mvs input.mpg -vf codecview=mv=fp+bp:frames=pf+bf
 @end example
diff --git a/libavfilter/vf_codecview.c b/libavfilter/vf_codecview.c
index d9ee8b0..6ffa3fc 100644
--- a/libavfilter/vf_codecview.c
+++ b/libavfilter/vf_codecview.c
@@ -37,8 +37,9 @@
 
 #define MV_FOR  (1<<0)
 #define MV_BACK (1<<1)
-#define FRAME_TYPE_P (1<<0)
-#define FRAME_TYPE_B (1<<1)
+#define FRAME_TYPE_I (1<<0)
+#define FRAME_TYPE_P (1<<1)
+#define FRAME_TYPE_B (1<<2)
 
 typedef struct {
     const AVClass *class;
@@ -56,7 +57,8 @@ static const AVOption codecview_options[] = {
     { "mv", "set motion vectors to visualize", OFFSET(mv), AV_OPT_TYPE_FLAGS, {.i64=0}, 0, INT_MAX, FLAGS, "mv" },
         CONST("fp", "forward predicted MVs",  MV_FOR,  "mv"),
         CONST("bp", "backward predicted MVs", MV_BACK, "mv"),
-    { "frames", "set frame types to display MVs of", OFFSET(frames), AV_OPT_TYPE_FLAGS, {.i64=3}, 0, INT_MAX, FLAGS, "frames" },
+    { "frames", "set frame types to display MVs of", OFFSET(frames), AV_OPT_TYPE_FLAGS, {.i64=7}, 0, INT_MAX, FLAGS, "frames" },
+        CONST("if", "i-frames", FRAME_TYPE_I, "frames"),
         CONST("pf", "p-frames", FRAME_TYPE_P, "frames"),
         CONST("bf", "b-frames", FRAME_TYPE_B, "frames"),
     { "qp", NULL, OFFSET(qp), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, .flags = FLAGS },
@@ -238,8 +240,10 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
             for (i = 0; i < sd->size / sizeof(*mvs); i++) {
                 const AVMotionVector *mv = &mvs[i];
                 const int direction = mv->source > 0;
-                if ((direction == 0 && (s->mv & MV_FOR)  && (s->frames & FRAME_TYPE_P) && frame->pict_type == AV_PICTURE_TYPE_P) ||
+                if ((direction == 0 && (s->mv & MV_FOR)  && (s->frames & FRAME_TYPE_I) && frame->pict_type == AV_PICTURE_TYPE_I) ||
+                    (direction == 0 && (s->mv & MV_FOR)  && (s->frames & FRAME_TYPE_P) && frame->pict_type == AV_PICTURE_TYPE_P) ||
                     (direction == 0 && (s->mv & MV_FOR)  && (s->frames & FRAME_TYPE_B) && frame->pict_type == AV_PICTURE_TYPE_B) ||
+                    (direction == 1 && (s->mv & MV_BACK) && (s->frames & FRAME_TYPE_I) && frame->pict_type == AV_PICTURE_TYPE_I) ||
                     (direction == 1 && (s->mv & MV_BACK) && (s->frames & FRAME_TYPE_B) && frame->pict_type == AV_PICTURE_TYPE_B))
                     draw_arrow(frame->data[0], mv->dst_x, mv->dst_y, mv->src_x, mv->src_y,
                                frame->width, frame->height, frame->linesize[0],
-- 
2.7.4 (Apple Git-66)

