History

avfilter/vf_v360: allow user to control fov for equirectagular format

It may be useful to use different values from typical 360/180 deg.

Paul B Mahol committed 5 years ago

Commit 1050f941 parent 282682a1 file · +103 −11Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/vf_v360.c+103−11
@@ -148,8 +148,8 @@ static const AVOption v360_options[] = { · 147 unmodified lines
148 { "pitch", "pitch rotation", OFFSET(pitch), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180.f, 180.f,TFLAGS, "pitch"},148 { "pitch", "pitch rotation", OFFSET(pitch), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180.f, 180.f,TFLAGS, "pitch"},
149 { "roll", "roll rotation", OFFSET(roll), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180.f, 180.f,TFLAGS, "roll"},149 { "roll", "roll rotation", OFFSET(roll), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180.f, 180.f,TFLAGS, "roll"},
150 { "rorder", "rotation order", OFFSET(rorder), AV_OPT_TYPE_STRING, {.str="ypr"}, 0, 0,TFLAGS, "rorder"},150 { "rorder", "rotation order", OFFSET(rorder), AV_OPT_TYPE_STRING, {.str="ypr"}, 0, 0,TFLAGS, "rorder"},
151 { "h_fov", "output horizontal field of view",OFFSET(h_fov), AV_OPT_TYPE_FLOAT, {.dbl=90.f}, 0.00001f, 360.f,TFLAGS, "h_fov"},151 { "h_fov", "output horizontal field of view",OFFSET(h_fov), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, 0.f, 360.f,TFLAGS, "h_fov"},
152 { "v_fov", "output vertical field of view", OFFSET(v_fov), AV_OPT_TYPE_FLOAT, {.dbl=45.f}, 0.00001f, 360.f,TFLAGS, "v_fov"},152 { "v_fov", "output vertical field of view", OFFSET(v_fov), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, 0.f, 360.f,TFLAGS, "v_fov"},
153 { "d_fov", "output diagonal field of view", OFFSET(d_fov), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, 0.f, 360.f,TFLAGS, "d_fov"},153 { "d_fov", "output diagonal field of view", OFFSET(d_fov), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, 0.f, 360.f,TFLAGS, "d_fov"},
154 { "h_flip", "flip out video horizontally", OFFSET(h_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1,TFLAGS, "h_flip"},154 { "h_flip", "flip out video horizontally", OFFSET(h_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1,TFLAGS, "h_flip"},
155 { "v_flip", "flip out video vertically", OFFSET(v_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1,TFLAGS, "v_flip"},155 { "v_flip", "flip out video vertically", OFFSET(v_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1,TFLAGS, "v_flip"},
@@ -158,8 +158,8 @@ static const AVOption v360_options[] = { · 2 unmodified lines
158 { "iv_flip", "flip in video vertically", OFFSET(iv_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1,TFLAGS, "iv_flip"},158 { "iv_flip", "flip in video vertically", OFFSET(iv_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1,TFLAGS, "iv_flip"},
159 { "in_trans", "transpose video input", OFFSET(in_transpose), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "in_transpose"},159 { "in_trans", "transpose video input", OFFSET(in_transpose), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "in_transpose"},
160 { "out_trans", "transpose video output", OFFSET(out_transpose), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "out_transpose"},160 { "out_trans", "transpose video output", OFFSET(out_transpose), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "out_transpose"},
161 { "ih_fov", "input horizontal field of view",OFFSET(ih_fov), AV_OPT_TYPE_FLOAT, {.dbl=90.f}, 0.00001f, 360.f,TFLAGS, "ih_fov"},161 { "ih_fov", "input horizontal field of view",OFFSET(ih_fov), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, 0.f, 360.f,TFLAGS, "ih_fov"},
162 { "iv_fov", "input vertical field of view", OFFSET(iv_fov), AV_OPT_TYPE_FLOAT, {.dbl=45.f}, 0.00001f, 360.f,TFLAGS, "iv_fov"},162 { "iv_fov", "input vertical field of view", OFFSET(iv_fov), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, 0.f, 360.f,TFLAGS, "iv_fov"},
163 { "id_fov", "input diagonal field of view", OFFSET(id_fov), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, 0.f, 360.f,TFLAGS, "id_fov"},163 { "id_fov", "input diagonal field of view", OFFSET(id_fov), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, 0.f, 360.f,TFLAGS, "id_fov"},
164 {"alpha_mask", "build mask in alpha plane", OFFSET(alpha), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "alpha"},164 {"alpha_mask", "build mask in alpha plane", OFFSET(alpha), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "alpha"},
165 { NULL }165 { NULL }
@@ -1728,6 +1728,23 @@ static int xyz_to_cube6x1(const V360Context *s, · 1562 unmodified lines
1728 return 1;1728 return 1;
1729}1729}
1730 1730
1731/**
1732 * Prepare data for processing equirectangular output format.
1733 *
1734 * @param ctx filter context
1735 *
1736 * @return error code
1737 */
1738static int prepare_equirect_out(AVFilterContext *ctx)
1739{
1740 V360Context *s = ctx->priv;
1741
1742 s->flat_range[0] = s->h_fov * M_PI / 360.f;
1743 s->flat_range[1] = s->v_fov * M_PI / 360.f;
1744
1745 return 0;
1746}
1747
1731/**1748/**
1732 * Calculate 3D coordinates on sphere for corresponding frame position in equirectangular format.1749 * Calculate 3D coordinates on sphere for corresponding frame position in equirectangular format.
1733 *1750 *
@@ -1742,8 +1759,8 @@ static int equirect_to_xyz(const V360Context *s, · 8 unmodified lines
1742 int i, int j, int width, int height,1759 int i, int j, int width, int height,
1743 float *vec)1760 float *vec)
1744{1761{
1745 const float phi = ((2.f * i + 0.5f) / width - 1.f) * M_PI;1762 const float phi = ((2.f * i + 0.5f) / width - 1.f) * s->flat_range[0];
1746 const float theta = ((2.f * j + 0.5f) / height - 1.f) * M_PI_2;1763 const float theta = ((2.f * j + 0.5f) / height - 1.f) * s->flat_range[1];
1747 1764
1748 const float sin_phi = sinf(phi);1765 const float sin_phi = sinf(phi);
1749 const float cos_phi = cosf(phi);1766 const float cos_phi = cosf(phi);
@@ -2103,6 +2120,23 @@ static int xyz_to_orthographic(const V360Context *s, · 353 unmodified lines
2103 return visible;2120 return visible;
2104}2121}
2105 2122
2123/**
2124 * Prepare data for processing equirectangular input format.
2125 *
2126 * @param ctx filter context
2127 *
2128 * @return error code
2129 */
2130static int prepare_equirect_in(AVFilterContext *ctx)
2131{
2132 V360Context *s = ctx->priv;
2133
2134 s->iflat_range[0] = s->ih_fov * M_PI / 360.f;
2135 s->iflat_range[1] = s->iv_fov * M_PI / 360.f;
2136
2137 return 0;
2138}
2139
2106/**2140/**
2107 * Calculate frame position in equirectangular format for corresponding 3D coordinates on sphere.2141 * Calculate frame position in equirectangular format for corresponding 3D coordinates on sphere.
2108 *2142 *
@@ -2122,15 +2156,18 @@ static int xyz_to_equirect(const V360Context *s, · 13 unmodified lines
2122 const float phi = atan2f(vec[0], vec[2]);2156 const float phi = atan2f(vec[0], vec[2]);
2123 const float theta = asinf(vec[1]);2157 const float theta = asinf(vec[1]);
2124 2158
2125 const float uf = (phi / M_PI + 1.f) * width / 2.f;2159 const float uf = (phi / s->iflat_range[0] + 1.f) * width / 2.f;
2126 const float vf = (theta / M_PI_2 + 1.f) * height / 2.f;2160 const float vf = (theta / s->iflat_range[1] + 1.f) * height / 2.f;
2127 2161
2128 const int ui = floorf(uf);2162 const int ui = floorf(uf);
2129 const int vi = floorf(vf);2163 const int vi = floorf(vf);
2164 int visible;
2130 2165
2131 *du = uf - ui;2166 *du = uf - ui;
2132 *dv = vf - vi;2167 *dv = vf - vi;
2133 2168
2169 visible = vi >= 0 && vi < height && ui >= 0 && ui < width;
2170
2134 for (int i = 0; i < 4; i++) {2171 for (int i = 0; i < 4; i++) {
2135 for (int j = 0; j < 4; j++) {2172 for (int j = 0; j < 4; j++) {
2136 us[i][j] = ereflectx(ui + j - 1, vi + i - 1, width, height);2173 us[i][j] = ereflectx(ui + j - 1, vi + i - 1, width, height);
@@ -2138,7 +2175,7 @@ static int xyz_to_equirect(const V360Context *s, · 1 unmodified line
2138 }2175 }
2139 }2176 }
2140 2177
2141 return 1;2178 return visible;
2142}2179}
2143 2180
2144/**2181/**
@@ -4003,6 +4040,10 @@ static int allocate_plane(V360Context *s, int sizeof_uv, int sizeof_ker, int siz · 1858 unmodified lines
4003static void fov_from_dfov(int format, float d_fov, float w, float h, float *h_fov, float *v_fov)4040static void fov_from_dfov(int format, float d_fov, float w, float h, float *h_fov, float *v_fov)
4004{4041{
4005 switch (format) {4042 switch (format) {
4043 case EQUIRECTANGULAR:
4044 *h_fov = d_fov;
4045 *v_fov = d_fov * 0.5f;
4046 break;
4006 case ORTHOGRAPHIC:4047 case ORTHOGRAPHIC:
4007 {4048 {
4008 const float d = 0.5f * hypotf(w, h);4049 const float d = 0.5f * hypotf(w, h);
@@ -4145,6 +4186,10 @@ static int config_output(AVFilterLink *outlink) · 136 unmodified lines
4145 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);4186 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
4146 const int depth = desc->comp[0].depth;4187 const int depth = desc->comp[0].depth;
4147 const int sizeof_mask = s->mask_size = (depth + 7) >> 3;4188 const int sizeof_mask = s->mask_size = (depth + 7) >> 3;
4189 float default_h_fov = 360.f;
4190 float default_v_fov = 180.f;
4191 float default_ih_fov = 360.f;
4192 float default_iv_fov = 180.f;
4148 int sizeof_uv;4193 int sizeof_uv;
4149 int sizeof_ker;4194 int sizeof_ker;
4150 int err;4195 int err;
@@ -4274,6 +4319,29 @@ static int config_output(AVFilterLink *outlink) · 123 unmodified lines
4274 s->in_width = s->inplanewidth[0];4319 s->in_width = s->inplanewidth[0];
4275 s->in_height = s->inplaneheight[0];4320 s->in_height = s->inplaneheight[0];
4276 4321
4322 switch (s->in) {
4323 case CYLINDRICAL:
4324 case FLAT:
4325 default_ih_fov = 90.f;
4326 default_iv_fov = 45.f;
4327 break;
4328 case EQUISOLID:
4329 case ORTHOGRAPHIC:
4330 case STEREOGRAPHIC:
4331 case DUAL_FISHEYE:
4332 case FISHEYE:
4333 default_ih_fov = 180.f;
4334 default_iv_fov = 180.f;
4335 default:
4336 break;
4337 }
4338
4339 if (s->ih_fov == 0.f)
4340 s->ih_fov = default_ih_fov;
4341
4342 if (s->iv_fov == 0.f)
4343 s->iv_fov = default_iv_fov;
4344
4277 if (s->id_fov > 0.f)4345 if (s->id_fov > 0.f)
4278 fov_from_dfov(s->in, s->id_fov, w, h, &s->ih_fov, &s->iv_fov);4346 fov_from_dfov(s->in, s->id_fov, w, h, &s->ih_fov, &s->iv_fov);
4279 4347
@@ -4283,7 +4351,7 @@ static int config_output(AVFilterLink *outlink) · 3 unmodified lines
4283 switch (s->in) {4351 switch (s->in) {
4284 case EQUIRECTANGULAR:4352 case EQUIRECTANGULAR:
4285 s->in_transform = xyz_to_equirect;4353 s->in_transform = xyz_to_equirect;
4286 err = 0;4354 err = prepare_equirect_in(ctx);
4287 wf = w;4355 wf = w;
4288 hf = h;4356 hf = h;
4289 break;4357 break;
@@ -4434,7 +4502,7 @@ static int config_output(AVFilterLink *outlink) · 144 unmodified lines
4434 switch (s->out) {4502 switch (s->out) {
4435 case EQUIRECTANGULAR:4503 case EQUIRECTANGULAR:
4436 s->out_transform = equirect_to_xyz;4504 s->out_transform = equirect_to_xyz;
4437 prepare_out = NULL;4505 prepare_out = prepare_equirect_out;
4438 w = lrintf(wf);4506 w = lrintf(wf);
4439 h = lrintf(hf);4507 h = lrintf(hf);
4440 break;4508 break;
@@ -4607,6 +4675,30 @@ static int config_output(AVFilterLink *outlink) · 166 unmodified lines
4607 s->width = w;4675 s->width = w;
4608 s->height = h;4676 s->height = h;
4609 4677
4678 switch (s->out) {
4679 case CYLINDRICAL:
4680 case FLAT:
4681 default_h_fov = 90.f;
4682 default_v_fov = 45.f;
4683 break;
4684 case EQUISOLID:
4685 case ORTHOGRAPHIC:
4686 case STEREOGRAPHIC:
4687 case DUAL_FISHEYE:
4688 case FISHEYE:
4689 default_h_fov = 180.f;
4690 default_v_fov = 180.f;
4691 break;
4692 default:
4693 break;
4694 }
4695
4696 if (s->h_fov == 0.f)
4697 s->h_fov = default_h_fov;
4698
4699 if (s->v_fov == 0.f)
4700 s->v_fov = default_v_fov;
4701
4610 if (s->d_fov > 0.f)4702 if (s->d_fov > 0.f)
4611 fov_from_dfov(s->out, s->d_fov, w, h, &s->h_fov, &s->v_fov);4703 fov_from_dfov(s->out, s->d_fov, w, h, &s->h_fov, &s->v_fov);
4612 4704

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t