[FFmpeg-cvslog] avfilter/vf_v360: add support for cylindrical input format

Paul B Mahol git at videolan.org
Tue Jan 21 01:25:55 EET 2020


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Mon Jan 20 23:29:14 2020 +0100| [19f75e77870ac8bca06d379c2ac2c3d652e6d08b] | committer: Paul B Mahol

avfilter/vf_v360: add support for cylindrical input format

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

 doc/filters.texi      |  7 ++++++
 libavfilter/vf_v360.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 1154638f95..421d65764b 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -19010,6 +19010,13 @@ Format specific options:
 @item d_fov
 Set horizontal/vertical/diagonal field of view. Values in degrees.
 
+If diagonal field of view is set it overrides horizontal and vertical field of view.
+
+ at item ih_fov
+ at item iv_fov
+ at 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 48090e8cb6..0c5c6a7775 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" },
+    {"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" },
     {  "equirect", "equirectangular",                            0, AV_OPT_TYPE_CONST,  {.i64=EQUIRECTANGULAR}, 0,                   0, FLAGS, "out" },
@@ -2406,6 +2407,64 @@ static void cylindrical_to_xyz(const V360Context *s,
     normalize_vector(vec);
 }
 
+/**
+ * Prepare data for processing cylindrical input format.
+ *
+ * @param ctx filter context
+ *
+ * @return error code
+ */
+static int prepare_cylindrical_in(AVFilterContext *ctx)
+{
+    V360Context *s = ctx->priv;
+
+    s->iflat_range[0] = M_PI * s->ih_fov / 360.f;
+    s->iflat_range[1] = tanf(0.5f * s->iv_fov * M_PI / 180.f);
+
+    return 0;
+}
+
+/**
+ * Calculate frame position in cylindrical 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_cylindrical(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 phi   = atan2f(vec[0], -vec[2]) * s->input_mirror_modifier[0] / s->iflat_range[0];
+    const float theta = atan2f(-vec[1], hypotf(vec[0], vec[2])) * s->input_mirror_modifier[1] / s->iflat_range[1];
+    int visible, ui, vi;
+    float uf, vf;
+
+    uf = (phi + 1.f) * (width - 1) / 2.f;
+    vf = (tanf(theta) + 1.f) * height / 2.f;
+    ui = floorf(uf);
+    vi = floorf(vf);
+
+    visible = vi >= 0 && vi < height && ui >= 0 && ui < width &&
+              theta <=  M_PI * s->iv_fov / 180.f &&
+              theta >= -M_PI * s->iv_fov / 180.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 perspective format.
  *
@@ -3011,7 +3070,6 @@ static int config_output(AVFilterLink *outlink)
         hf = h;
         break;
     case PERSPECTIVE:
-    case CYLINDRICAL:
     case PANNINI:
     case FISHEYE:
         av_log(ctx, AV_LOG_ERROR, "Supplied format is not accepted as input.\n");
@@ -3058,6 +3116,12 @@ static int config_output(AVFilterLink *outlink)
         wf = w;
         hf = h;
         break;
+    case CYLINDRICAL:
+        s->in_transform = xyz_to_cylindrical;
+        err = prepare_cylindrical_in(ctx);
+        wf = w;
+        hf = h * 2.f;
+        break;
     default:
         av_log(ctx, AV_LOG_ERROR, "Specified input format is not handled.\n");
         return AVERROR_BUG;



More information about the ffmpeg-cvslog mailing list