ffmpeg | branch: master | Paul B Mahol <[email protected]> | Tue Jan 21 18:42:46 
2020 +0100| [103a29b89d6e0cd0fdc5d7a715cbf3212fe33684] | committer: Paul B Mahol

avfilter/vf_v360: add support for fisheye input format

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=103a29b89d6e0cd0fdc5d7a715cbf3212fe33684
---

 doc/filters.texi      | 11 +++++++--
 libavfilter/vf_v360.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 74 insertions(+), 3 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index cfca90d12e..fc900cf458 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -18986,14 +18986,21 @@ Hammer-Aitoff map projection format.
 Sinusoidal map projection format.
 
 @item fisheye
-Fisheye projection. @i{(output only)}
+Fisheye projection.
 
 Format specific options:
 @table @option
 @item h_fov
 @item v_fov
 @item d_fov
-Set horizontal/vertical/diagonal field of view. Values in degrees.
+Set output horizontal/vertical/diagonal field of view. Values in degrees.
+
+If diagonal field of view is set it overrides horizontal and vertical field of 
view.
+
+@item ih_fov
+@item iv_fov
+@item id_fov
+Set input horizontal/vertical/diagonal field of view. Values in degrees.
 
 If diagonal field of view is set it overrides horizontal and vertical field of 
view.
 @end table
diff --git a/libavfilter/vf_v360.c b/libavfilter/vf_v360.c
index 2570dc36af..c4a5926db7 100644
--- a/libavfilter/vf_v360.c
+++ b/libavfilter/vf_v360.c
@@ -72,6 +72,7 @@ static const AVOption v360_options[] = {
     {      "ball", "ball",                                       0, 
AV_OPT_TYPE_CONST,  {.i64=BALL},            0,                   0, FLAGS, "in" 
},
     {    "hammer", "hammer",                                     0, 
AV_OPT_TYPE_CONST,  {.i64=HAMMER},          0,                   0, FLAGS, "in" 
},
     {"sinusoidal", "sinusoidal",                                 0, 
AV_OPT_TYPE_CONST,  {.i64=SINUSOIDAL},      0,                   0, FLAGS, "in" 
},
+    {   "fisheye", "fisheye",                                    0, 
AV_OPT_TYPE_CONST,  {.i64=FISHEYE},         0,                   0, FLAGS, "in" 
},
     {"cylindrical", "cylindrical",                               0, 
AV_OPT_TYPE_CONST,  {.i64=CYLINDRICAL},     0,                   0, FLAGS, "in" 
},
     {    "output", "set output projection",            OFFSET(out), 
AV_OPT_TYPE_INT,    {.i64=CUBEMAP_3_2},     0,    NB_PROJECTIONS-1, FLAGS, 
"out" },
     {         "e", "equirectangular",                            0, 
AV_OPT_TYPE_CONST,  {.i64=EQUIRECTANGULAR}, 0,                   0, FLAGS, 
"out" },
@@ -2345,6 +2346,64 @@ static void fisheye_to_xyz(const V360Context *s,
     normalize_vector(vec);
 }
 
+/**
+ * Prepare data for processing fisheye input format.
+ *
+ * @param ctx filter context
+ *
+ * @return error code
+ */
+static int prepare_fisheye_in(AVFilterContext *ctx)
+{
+    V360Context *s = ctx->priv;
+
+    s->iflat_range[0] = s->ih_fov / 180.f;
+    s->iflat_range[1] = s->iv_fov / 180.f;
+
+    return 0;
+}
+
+/**
+ * Calculate frame position in fisheye format for corresponding 3D coordinates 
on sphere.
+ *
+ * @param s filter private context
+ * @param vec coordinates on sphere
+ * @param width frame width
+ * @param height frame height
+ * @param us horizontal coordinates for interpolation window
+ * @param vs vertical coordinates for interpolation window
+ * @param du horizontal relative coordinate
+ * @param dv vertical relative coordinate
+ */
+static void xyz_to_fisheye(const V360Context *s,
+                           const float *vec, int width, int height,
+                           int16_t us[4][4], int16_t vs[4][4], float *du, 
float *dv)
+{
+    const float h     = hypotf(vec[0], vec[1]);
+    const float lh    = h > 0.f ? h : 1.f;
+    const float theta = acosf(fabsf(vec[2])) / M_PI;
+
+    const float uf = (theta * ( vec[0] / lh) * s->input_mirror_modifier[0] / 
s->iflat_range[0] + 0.5f) * width;
+    const float vf = (theta * (-vec[1] / lh) * s->input_mirror_modifier[1] / 
s->iflat_range[1] + 0.5f) * height;
+
+    int visible, ui, vi;
+
+    ui = floorf(uf);
+    vi = floorf(vf);
+
+    visible = vec[2] < 0.f;
+
+    *du = uf - ui;
+    *dv = vf - vi;
+
+    for (int i = -1; i < 3; i++) {
+        for (int j = -1; j < 3; j++) {
+            us[i + 1][j + 1] = visible ? av_clip(ui + j, 0, width  - 1) : 0;
+            vs[i + 1][j + 1] = visible ? av_clip(vi + i, 0, height - 1) : 0;
+        }
+    }
+}
+
 /**
  * Calculate 3D coordinates on sphere for corresponding frame position in 
pannini format.
  *
@@ -3090,7 +3149,6 @@ static int config_output(AVFilterLink *outlink)
         break;
     case PERSPECTIVE:
     case PANNINI:
-    case FISHEYE:
         av_log(ctx, AV_LOG_ERROR, "Supplied format is not accepted as 
input.\n");
         return AVERROR(EINVAL);
     case DUAL_FISHEYE:
@@ -3135,6 +3193,12 @@ static int config_output(AVFilterLink *outlink)
         wf = w;
         hf = h;
         break;
+    case FISHEYE:
+        s->in_transform = xyz_to_fisheye;
+        err = prepare_fisheye_in(ctx);
+        wf = w * 2;
+        hf = h;
+        break;
     case CYLINDRICAL:
         s->in_transform = xyz_to_cylindrical;
         err = prepare_cylindrical_in(ctx);

_______________________________________________
ffmpeg-cvslog mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".

Reply via email to