[FFmpeg-cvslog] avfilter/vf_v360: add support for stereographic as input projection

Paul B Mahol git at videolan.org
Tue Sep 10 20:00:16 EEST 2019


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Tue Sep 10 18:56:03 2019 +0200| [329505d9088507dec82fae6e54b2da173a5389d7] | committer: Paul B Mahol

avfilter/vf_v360: add support for stereographic as input projection

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

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

diff --git a/doc/filters.texi b/doc/filters.texi
index 2bf197293f..22c8687bdf 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -18033,7 +18033,7 @@ Default value is @b{@samp{0}}.
 Facebook's 360 format.
 
 @item sg
-Stereographic format. @i{(output only)}
+Stereographic format.
 
 Format specific options:
 @table @option
diff --git a/libavfilter/vf_v360.c b/libavfilter/vf_v360.c
index 347e0db63a..b0a99a498d 100644
--- a/libavfilter/vf_v360.c
+++ b/libavfilter/vf_v360.c
@@ -64,6 +64,7 @@ static const AVOption v360_options[] = {
     {    "barrel", "barrel facebook's 360 format",               0, AV_OPT_TYPE_CONST,  {.i64=BARREL},          0,                   0, FLAGS, "in" },
     {        "fb", "barrel facebook's 360 format",               0, AV_OPT_TYPE_CONST,  {.i64=BARREL},          0,                   0, FLAGS, "in" },
     {      "c1x6", "cubemap 1x6",                                0, AV_OPT_TYPE_CONST,  {.i64=CUBEMAP_1_6},     0,                   0, FLAGS, "in" },
+    {        "sg", "stereographic",                              0, AV_OPT_TYPE_CONST,  {.i64=STEREOGRAPHIC},   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" },
@@ -1421,6 +1422,44 @@ static void stereographic_to_xyz(const V360Context *s,
 }
 
 /**
+ * Calculate frame position in stereographic format for corresponding 3D coordinates on sphere.
+ *
+ * @param s filter 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_stereographic(const V360Context *s,
+                                 const float *vec, int width, int height,
+                                 uint16_t us[4][4], uint16_t vs[4][4], float *du, float *dv)
+{
+    const float x = av_clipf(vec[0] / (1.f - vec[1]), -1.f, 1.f) * s->input_mirror_modifier[0];
+    const float y = av_clipf(vec[2] / (1.f - vec[1]), -1.f, 1.f) * s->input_mirror_modifier[1];
+    float uf, vf;
+    int ui, vi;
+    int i, j;
+
+    uf = (x + 1.f) * width  / 2.f;
+    vf = (y + 1.f) * height / 2.f;
+    ui = floorf(uf);
+    vi = floorf(vf);
+
+    *du = uf - ui;
+    *dv = vf - vi;
+
+    for (i = -1; i < 3; i++) {
+        for (j = -1; j < 3; j++) {
+            us[i + 1][j + 1] = av_clip(ui + j, 0, width - 1);
+            vs[i + 1][j + 1] = av_clip(vi + i, 0, height - 1);
+        }
+    }
+}
+
+/**
  * Calculate frame position in equirectangular format for corresponding 3D coordinates on sphere.
  *
  * @param s filter context
@@ -2177,6 +2216,12 @@ static int config_output(AVFilterLink *outlink)
         wf = inlink->w / 5.f * 4.f;
         hf = inlink->h;
         break;
+    case STEREOGRAPHIC:
+        in_transform = xyz_to_stereographic;
+        err = 0;
+        wf = inlink->w;
+        hf = inlink->h;
+        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