summaryrefslogtreecommitdiff
path: root/libavfilter
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2020-03-03 12:03:42 +0100
committerPaul B Mahol <onemda@gmail.com>2020-03-03 12:03:42 +0100
commitca0423198304305d832304e218611fb5d61921b3 (patch)
tree4c64defe059b0ac052c090783bdc0d2db160c662 /libavfilter
parentf9cb7cf424054ea098cb0e329ba49efb41d02b7c (diff)
avfilter/vf_v360: add half equirectangular output format
Diffstat (limited to 'libavfilter')
-rw-r--r--libavfilter/v360.h1
-rw-r--r--libavfilter/vf_v360.c37
2 files changed, 38 insertions, 0 deletions
diff --git a/libavfilter/v360.h b/libavfilter/v360.h
index 4b2351f177..f2f1a47144 100644
--- a/libavfilter/v360.h
+++ b/libavfilter/v360.h
@@ -50,6 +50,7 @@ enum Projections {
TETRAHEDRON,
BARREL_SPLIT,
TSPYRAMID,
+ HEQUIRECTANGULAR,
NB_PROJECTIONS,
};
diff --git a/libavfilter/vf_v360.c b/libavfilter/vf_v360.c
index 5cbf8c95b1..3d4ee25216 100644
--- a/libavfilter/vf_v360.c
+++ b/libavfilter/vf_v360.c
@@ -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" },
@@ -1631,6 +1633,35 @@ static int equirect_to_xyz(const V360Context *s,
}
/**
+ * 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.
*
* @param ctx filter context
@@ -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;