summaryrefslogtreecommitdiff
path: root/libavfilter
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2020-02-26 21:23:59 +0100
committerPaul B Mahol <onemda@gmail.com>2020-02-27 23:37:23 +0100
commit9b22254331e9b83f7d0006b1559b39033d801959 (patch)
tree1e8c2f0f8022e41c7cce681f4c4ffd3dda554cb2 /libavfilter
parenta2c97a8342fab6393280cc2f0e2ffb39c381d29c (diff)
avfilter/vf_v360: add initial barrel split format input support
Diffstat (limited to 'libavfilter')
-rw-r--r--libavfilter/vf_v360.c148
1 files changed, 128 insertions, 20 deletions
diff --git a/libavfilter/vf_v360.c b/libavfilter/vf_v360.c
index 1dae2a3e4c..eedf4fe8b2 100644
--- a/libavfilter/vf_v360.c
+++ b/libavfilter/vf_v360.c
@@ -76,6 +76,7 @@ static const AVOption v360_options[] = {
{ "fisheye", "fisheye", 0, AV_OPT_TYPE_CONST, {.i64=FISHEYE}, 0, 0, FLAGS, "in" },
{"cylindrical", "cylindrical", 0, AV_OPT_TYPE_CONST, {.i64=CYLINDRICAL}, 0, 0, FLAGS, "in" },
{"tetrahedron", "tetrahedron", 0, AV_OPT_TYPE_CONST, {.i64=TETRAHEDRON}, 0, 0, FLAGS, "in" },
+ {"barrelsplit", "barrel split facebook's 360 format", 0, AV_OPT_TYPE_CONST, {.i64=BARREL_SPLIT}, 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" },
@@ -2892,7 +2893,7 @@ static int barrel_to_xyz(const V360Context *s,
float uf, vf;
if (j < eh) { // UP
- uf = 2.f * (i - 4 * ew) / ew - 1.f;
+ uf = 2.f * (i - 4 * ew) / ew - 1.f;
vf = 2.f * (j ) / eh - 1.f;
uf /= scale;
@@ -2999,6 +3000,105 @@ static int xyz_to_barrel(const V360Context *s,
}
/**
+ * Calculate frame position in barrel split facebook's 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 int xyz_to_barrelsplit(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];
+ const float theta = asinf(-vec[1]) * s->input_mirror_modifier[1];
+
+ const float theta_range = M_PI_4;
+
+ int ew, eh;
+ int u_shift, v_shift;
+ float uf, vf;
+ int ui, vi;
+
+ if (theta >= -theta_range && theta <= theta_range) {
+ const float scalew = s->fin_pad > 0 ? 1.f - s->fin_pad / (width * 2.f / 3.f) : 1.f - s->in_pad;
+ const float scaleh = s->fin_pad > 0 ? 1.f - s->fin_pad / (height / 2.f) : 1.f - s->in_pad;
+
+ ew = width / 3 * 2;
+ eh = height / 2;
+
+ u_shift = s->ih_flip ? width / 3 : 0;
+ v_shift = phi >= M_PI_2 || phi < -M_PI_2 ? eh : 0;
+
+ uf = fmodf(phi, M_PI_2) / M_PI_2;
+ vf = theta / M_PI_4;
+
+ if (v_shift)
+ uf = uf >= 0.f ? fmodf(uf - 1.f, 1.f) : fmodf(uf + 1.f, 1.f);
+
+ uf = (uf * scalew + 1.f) * width / 3.f;
+ vf = (vf * scaleh + 1.f) * height / 4.f;
+ } else {
+ const float scalew = s->fin_pad > 0 ? 1.f - s->fin_pad / (width / 3.f) : 1.f - s->in_pad;
+ const float scaleh = s->fin_pad > 0 ? 1.f - s->fin_pad / (height / 4.f) : 1.f - s->in_pad;
+ int v_offset = 0;
+
+ ew = width / 3;
+ eh = height / 4;
+
+ u_shift = s->ih_flip ? 0 : 2 * ew;
+
+ if (theta <= 0.f && theta >= -M_PI_2 &&
+ phi <= M_PI_2 && phi >= -M_PI_2) {
+ uf = vec[0] / vec[1];
+ vf = -vec[2] / vec[1];
+ v_shift = 0;
+ v_offset = -eh;
+ } else if (theta >= 0.f && theta <= M_PI_2 &&
+ phi <= M_PI_2 && phi >= -M_PI_2) {
+ uf = -vec[0] / vec[1];
+ vf = -vec[2] / vec[1];
+ v_shift = height * 0.25f;
+ } else if (theta <= 0.f && theta >= -M_PI_2) {
+ uf = -vec[0] / vec[1];
+ vf = vec[2] / vec[1];
+ v_shift = height * 0.5f;
+ v_offset = -eh;
+ } else {
+ uf = vec[0] / vec[1];
+ vf = vec[2] / vec[1];
+ v_shift = height * 0.75f;
+ }
+
+ uf *= s->input_mirror_modifier[0] * s->input_mirror_modifier[1];
+ vf *= s->input_mirror_modifier[1];
+
+ uf = 0.5f * width / 3.f * (uf * scalew + 1.f);
+ vf = height * 0.25f * (vf * scaleh + 1.f) + v_offset;
+ }
+
+ ui = floorf(uf);
+ vi = floorf(vf);
+
+ *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] = u_shift + av_clip(ui + j, 0, ew - 1);
+ vs[i + 1][j + 1] = v_shift + av_clip(vi + i, 0, eh - 1);
+ }
+ }
+
+ return 1;
+}
+
+/**
* Calculate 3D coordinates on sphere for corresponding frame position in barrel split facebook's format.
*
* @param s filter private context
@@ -3012,16 +3112,18 @@ static int barrelsplit_to_xyz(const V360Context *s,
int i, int j, int width, int height,
float *vec)
{
- const float scale = 1.01f;
const float x = (i + 0.5f) / width;
const float y = (j + 0.5f) / height;
float l_x, l_y, l_z;
- if (x <= 2.f / 3.f) {
+ if (x < 2.f / 3.f) {
+ const float scalew = s->fout_pad > 0 ? 1.f - s->fout_pad / (width * 2.f / 3.f) : 1.f - s->out_pad;
+ const float scaleh = s->fout_pad > 0 ? 1.f - s->fout_pad / (height / 2.f) : 1.f - s->out_pad;
+
const float back = floorf(y * 2.f);
- const float phi = ((3.f / 2.f * x - 0.5f) * scale - back + 1.f) * M_PI;
- const float theta = (y - 0.25f - 0.5f * back) * scale * M_PI;
+ const float phi = ((3.f / 2.f * x - 0.5f) / scalew - back + 1.f) * M_PI;
+ const float theta = (y - 0.25f - 0.5f * back) / scaleh * M_PI;
const float sin_phi = sinf(phi);
const float cos_phi = cosf(phi);
@@ -3032,46 +3134,47 @@ static int barrelsplit_to_xyz(const V360Context *s,
l_y = -sin_theta;
l_z = cos_theta * cos_phi;
} else {
+ const float scalew = s->fout_pad > 0 ? 1.f - s->fout_pad / (width / 3.f) : 1.f - s->out_pad;
+ const float scaleh = s->fout_pad > 0 ? 1.f - s->fout_pad / (height / 4.f) : 1.f - s->out_pad;
+
const int face = floorf(y * 4.f);
float uf, vf;
uf = x * 3.f - 2.f;
- uf = (uf - 0.5f) * scale + 0.5f;
switch (face) {
case 0:
vf = y * 2.f;
uf = 1.f - uf;
- vf = (0.5f - vf) * scale;
+ vf = 0.5f - vf;
- l_x = 0.5f - uf;
+ l_x = (0.5f - uf) / scalew;
l_y = 0.5f;
- l_z = -0.5f + vf;
+ l_z = (-0.5f + vf) / scaleh;
break;
case 1:
vf = y * 2.f;
uf = 1.f - uf;
- vf = 1.f - (vf - 0.5f) * scale;
+ vf = 1.f - (vf - 0.5f);
- l_x = 0.5f - uf;
+ l_x = (0.5f - uf) / scalew;
l_y = -0.5f;
- l_z = 0.5f - vf;
+ l_z = (0.5f - vf) / scaleh;
break;
case 2:
vf = y * 2.f - 0.5f;
- vf = 1.f - (1.f - vf) * scale;
+ vf = 1.f - (1.f - vf);
- l_x = 0.5f - uf;
- l_y = 0.5f;
- l_z = -0.5f + vf;
+ l_x = (0.5f - uf) / scalew;
+ l_y = 0.5f;
+ l_z = (-0.5f + vf) / scaleh;
break;
case 3:
vf = y * 2.f - 1.5f;
- vf = vf * scale;
- l_x = 0.5f - uf;
+ l_x = (0.5f - uf) / scalew;
l_y = -0.5f;
- l_z = 0.5f - vf;
+ l_z = (0.5f - vf) / scaleh;
break;
}
}
@@ -3456,7 +3559,6 @@ static int config_output(AVFilterLink *outlink)
wf = w;
hf = h;
break;
- case BARREL_SPLIT:
case PERSPECTIVE:
case PANNINI:
av_log(ctx, AV_LOG_ERROR, "Supplied format is not accepted as input.\n");
@@ -3521,6 +3623,12 @@ static int config_output(AVFilterLink *outlink)
wf = w;
hf = h;
break;
+ case BARREL_SPLIT:
+ s->in_transform = xyz_to_barrelsplit;
+ err = 0;
+ wf = w * 4.f / 3.f;
+ hf = h;
+ break;
default:
av_log(ctx, AV_LOG_ERROR, "Specified input format is not handled.\n");
return AVERROR_BUG;