summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2019-09-08 18:17:57 +0200
committerPaul B Mahol <onemda@gmail.com>2019-09-08 21:07:59 +0200
commit973051e3bd560900db8ac05725a1dd80bbff0362 (patch)
treea2c23428bbcf76a27c57b7ff5c808673e72dd7ba
parenta13b61b7fd05ac9dcf795b5f4cc22ec498557e49 (diff)
avfilter/vf_v360: add stereographic output projection
-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 0c26b54ec1..93ac8034ef 100644
--- a/libavfilter/v360.h
+++ b/libavfilter/v360.h
@@ -31,6 +31,7 @@ enum Projections {
DUAL_FISHEYE,
BARREL,
CUBEMAP_1_6,
+ STEREOGRAPHIC,
NB_PROJECTIONS,
};
diff --git a/libavfilter/vf_v360.c b/libavfilter/vf_v360.c
index 426697145b..13dffd9e15 100644
--- a/libavfilter/vf_v360.c
+++ b/libavfilter/vf_v360.c
@@ -74,6 +74,7 @@ static const AVOption v360_options[] = {
{ "barrel", "barrel facebook's 360 format", 0, AV_OPT_TYPE_CONST, {.i64=BARREL}, 0, 0, FLAGS, "out" },
{ "fb", "barrel facebook's 360 format", 0, AV_OPT_TYPE_CONST, {.i64=BARREL}, 0, 0, FLAGS, "out" },
{ "c1x6", "cubemap 1x6", 0, AV_OPT_TYPE_CONST, {.i64=CUBEMAP_1_6}, 0, 0, FLAGS, "out" },
+ { "sg", "stereographic", 0, AV_OPT_TYPE_CONST, {.i64=STEREOGRAPHIC}, 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" },
@@ -1378,6 +1379,36 @@ static void equirect_to_xyz(const V360Context *s,
}
/**
+ * Calculate 3D coordinates on sphere for corresponding frame position in stereographic format.
+ *
+ * @param s filter context
+ * @param i horizontal position on frame [0, height)
+ * @param j vertical position on frame [0, width)
+ * @param width frame width
+ * @param height frame height
+ * @param vec coordinates on sphere
+ */
+static void stereographic_to_xyz(const V360Context *s,
+ int i, int j, int width, int height,
+ float *vec)
+{
+ const float z = 0.5f * s->h_fov * M_PI / 180.f;
+ const float x = z * (2.f * i / width - 1.f);
+ const float y = z * (2.f * j / height - 1.f);
+ const float xy = x * x + y * y;
+ float norm;
+
+ vec[0] = 2.f * x / (1.f + xy);
+ vec[1] = (-1.f + xy) / (1.f + xy);
+ vec[2] = 2.f * y / (1.f + xy);
+
+ norm = sqrtf(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]);
+ vec[0] /= norm;
+ vec[1] /= norm;
+ vec[2] /= norm;
+}
+
+/**
* Calculate frame position in equirectangular format for corresponding 3D coordinates on sphere.
*
* @param s filter context
@@ -2194,6 +2225,12 @@ static int config_output(AVFilterLink *outlink)
w = roundf(wf / 4.f * 5.f);
h = roundf(hf);
break;
+ case STEREOGRAPHIC:
+ out_transform = stereographic_to_xyz;
+ err = 0;
+ w = FFMAX(roundf(wf), roundf(hf));
+ h = w;
+ break;
default:
av_log(ctx, AV_LOG_ERROR, "Specified output format is not handled.\n");
return AVERROR_BUG;