]> git.sesse.net Git - ffmpeg/commitdiff
avfilter/vf_v360: add half equirectangular output format
authorPaul B Mahol <onemda@gmail.com>
Tue, 3 Mar 2020 11:03:42 +0000 (12:03 +0100)
committerPaul B Mahol <onemda@gmail.com>
Tue, 3 Mar 2020 11:03:42 +0000 (12:03 +0100)
libavfilter/v360.h
libavfilter/vf_v360.c

index 4b2351f1778f616d001dcc20191649614c62a3e2..f2f1a47144d704534826490145f6fa48de3e5ee1 100644 (file)
@@ -50,6 +50,7 @@ enum Projections {
     TETRAHEDRON,
     BARREL_SPLIT,
     TSPYRAMID,
+    HEQUIRECTANGULAR,
     NB_PROJECTIONS,
 };
 
index 5cbf8c95b157bb10d9809f2bc40a27672887d826..3d4ee25216941bb7c2f99750291b37025b5645af 100644 (file)
@@ -103,6 +103,8 @@ static const AVOption v360_options[] = {
     {"tetrahedron", "tetrahedron",                               0, AV_OPT_TYPE_CONST,  {.i64=TETRAHEDRON},     0,                   0, FLAGS, "out" },
     {"barrelsplit", "barrel split facebook's 360 format",        0, AV_OPT_TYPE_CONST,  {.i64=BARREL_SPLIT},    0,                   0, FLAGS, "out" },
     {       "tsp", "truncated square pyramid",                   0, AV_OPT_TYPE_CONST,  {.i64=TSPYRAMID},       0,                   0, FLAGS, "out" },
+    { "hequirect", "half equirectangular",                       0, AV_OPT_TYPE_CONST,  {.i64=HEQUIRECTANGULAR},0,                   0, FLAGS, "out" },
+    {        "he", "half equirectangular",                       0, AV_OPT_TYPE_CONST,  {.i64=HEQUIRECTANGULAR},0,                   0, FLAGS, "out" },
     {    "interp", "set interpolation method",      OFFSET(interp), AV_OPT_TYPE_INT,    {.i64=BILINEAR},        0, NB_INTERP_METHODS-1, FLAGS, "interp" },
     {      "near", "nearest neighbour",                          0, AV_OPT_TYPE_CONST,  {.i64=NEAREST},         0,                   0, FLAGS, "interp" },
     {   "nearest", "nearest neighbour",                          0, AV_OPT_TYPE_CONST,  {.i64=NEAREST},         0,                   0, FLAGS, "interp" },
@@ -1630,6 +1632,35 @@ static int equirect_to_xyz(const V360Context *s,
     return 1;
 }
 
+/**
+ * Calculate 3D coordinates on sphere for corresponding frame position in half equirectangular format.
+ *
+ * @param s filter private context
+ * @param i horizontal position on frame [0, width)
+ * @param j vertical position on frame [0, height)
+ * @param width frame width
+ * @param height frame height
+ * @param vec coordinates on sphere
+ */
+static int hequirect_to_xyz(const V360Context *s,
+                            int i, int j, int width, int height,
+                            float *vec)
+{
+    const float phi   = ((2.f * i + 0.5f) / width  - 1.f) * M_PI_2;
+    const float theta = ((2.f * j + 0.5f) / height - 1.f) * M_PI_2;
+
+    const float sin_phi   = sinf(phi);
+    const float cos_phi   = cosf(phi);
+    const float sin_theta = sinf(theta);
+    const float cos_theta = cosf(theta);
+
+    vec[0] =  cos_theta * sin_phi;
+    vec[1] = -sin_theta;
+    vec[2] = -cos_theta * cos_phi;
+
+    return 1;
+}
+
 /**
  * Prepare data for processing stereographic output format.
  *
@@ -3934,6 +3965,12 @@ static int config_output(AVFilterLink *outlink)
         w = lrintf(wf);
         h = lrintf(hf);
         break;
+    case HEQUIRECTANGULAR:
+        s->out_transform = hequirect_to_xyz;
+        prepare_out = NULL;
+        w = lrintf(wf / 2.f);
+        h = lrintf(hf);
+        break;
     default:
         av_log(ctx, AV_LOG_ERROR, "Specified output format is not handled.\n");
         return AVERROR_BUG;