History

avfilter/vf_v360: implement diagonal field of view

Paul B Mahol committed 7 years ago

Commit cb8d6a41 parent 8efc9fc3 files · +43 −16Browse files

Unified · Split

3 files
  1. doc/filters.texi +8 −2
  2. libavfilter/v360.h +1 −1
  3. libavfilter/vf_v360.c +34 −13
doc/filters.texi+8−2
@@ -18006,7 +18006,10 @@ Format specific options: · 18005 unmodified lines
18006@table @option18006@table @option
18007@item h_fov18007@item h_fov
18008@item v_fov18008@item v_fov
18009Set horizontal/vertical field of view. Values in degrees.18009@item d_fov
18010Set horizontal/vertical/diagonal field of view. Values in degrees.
18011
18012If diagonal field of view is set it overrides horizontal and vertical field of view.
18010@end table18013@end table
18011 18014
18012@item dfisheye18015@item dfisheye
@@ -18040,7 +18043,10 @@ Format specific options: · 27 unmodified lines
18040@table @option18043@table @option
18041@item h_fov18044@item h_fov
18042@item v_fov18045@item v_fov
18043Set horizontal/vertical field of view. Values in degrees.18046@item d_fov
18047Set horizontal/vertical/diagonal field of view. Values in degrees.
18048
18049If diagonal field of view is set it overrides horizontal and vertical field of view.
18044@end table18050@end table
18045 18051
18046@end table18052@end table
libavfilter/v360.h+1−1
@@ -103,7 +103,7 @@ typedef struct V360Context { · 102 unmodified lines
103 int h_flip, v_flip, d_flip;103 int h_flip, v_flip, d_flip;
104 int in_transpose, out_transpose;104 int in_transpose, out_transpose;
105 105
106 float h_fov, v_fov;106 float h_fov, v_fov, d_fov;
107 float flat_range[3];107 float flat_range[3];
108 108
109 float input_mirror_modifier[2];109 float input_mirror_modifier[2];
libavfilter/vf_v360.c+34−13
@@ -102,6 +102,7 @@ static const AVOption v360_options[] = { · 101 unmodified lines
102 { "rorder", "rotation order", OFFSET(rorder), AV_OPT_TYPE_STRING, {.str="ypr"}, 0, 0, FLAGS, "rorder"},102 { "rorder", "rotation order", OFFSET(rorder), AV_OPT_TYPE_STRING, {.str="ypr"}, 0, 0, FLAGS, "rorder"},
103 { "h_fov", "horizontal field of view", OFFSET(h_fov), AV_OPT_TYPE_FLOAT, {.dbl=90.f}, 0.00001f, 360.f, FLAGS, "h_fov"},103 { "h_fov", "horizontal field of view", OFFSET(h_fov), AV_OPT_TYPE_FLOAT, {.dbl=90.f}, 0.00001f, 360.f, FLAGS, "h_fov"},
104 { "v_fov", "vertical field of view", OFFSET(v_fov), AV_OPT_TYPE_FLOAT, {.dbl=45.f}, 0.00001f, 360.f, FLAGS, "v_fov"},104 { "v_fov", "vertical field of view", OFFSET(v_fov), AV_OPT_TYPE_FLOAT, {.dbl=45.f}, 0.00001f, 360.f, FLAGS, "v_fov"},
105 { "d_fov", "diagonal field of view", OFFSET(d_fov), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, 0.f, 360.f, FLAGS, "d_fov"},
105 { "h_flip", "flip out video horizontally", OFFSET(h_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "h_flip"},106 { "h_flip", "flip out video horizontally", OFFSET(h_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "h_flip"},
106 { "v_flip", "flip out video vertically", OFFSET(v_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "v_flip"},107 { "v_flip", "flip out video vertically", OFFSET(v_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "v_flip"},
107 { "d_flip", "flip out video indepth", OFFSET(d_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "d_flip"},108 { "d_flip", "flip out video indepth", OFFSET(d_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "d_flip"},
@@ -2139,6 +2140,20 @@ static int allocate_plane(V360Context *s, int sizeof_uv, int sizeof_ker, int p) · 2031 unmodified lines
2139 return 0;2140 return 0;
2140}2141}
2141 2142
2143static void fov_from_dfov(V360Context *s, float w, float h)
2144{
2145 const float d_angle = 0.5 * FFMIN(s->d_fov, 359.f) * M_PI / 180.f;
2146 const float d = hypotf(w, h);
2147
2148 s->h_fov = atan2f(tanf(d_angle) * w, d) * 360.f / M_PI;
2149 s->v_fov = atan2f(tanf(d_angle) * h, d) * 360.f / M_PI;
2150
2151 if (s->h_fov < 0.f)
2152 s->h_fov += 360.f;
2153 if (s->v_fov < 0.f)
2154 s->v_fov += 360.f;
2155}
2156
2142static int config_output(AVFilterLink *outlink)2157static int config_output(AVFilterLink *outlink)
2143{2158{
2144 AVFilterContext *ctx = outlink->src;2159 AVFilterContext *ctx = outlink->src;
@@ -2161,6 +2176,7 @@ static int config_output(AVFilterLink *outlink) · 16 unmodified lines
2161 float *vec);2176 float *vec);
2162 void (*calculate_kernel)(float du, float dv, const XYRemap *r_tmp,2177 void (*calculate_kernel)(float du, float dv, const XYRemap *r_tmp,
2163 uint16_t *u, uint16_t *v, int16_t *ker);2178 uint16_t *u, uint16_t *v, int16_t *ker);
2179 int (*prepare_out)(AVFilterContext *ctx);
2164 float rot_mat[3][3];2180 float rot_mat[3][3];
2165 2181
2166 s->input_mirror_modifier[0] = s->ih_flip ? -1.f : 1.f;2182 s->input_mirror_modifier[0] = s->ih_flip ? -1.f : 1.f;
@@ -2285,55 +2301,55 @@ static int config_output(AVFilterLink *outlink) · 118 unmodified lines
2285 switch (s->out) {2301 switch (s->out) {
2286 case EQUIRECTANGULAR:2302 case EQUIRECTANGULAR:
2287 out_transform = equirect_to_xyz;2303 out_transform = equirect_to_xyz;
2288 err = 0;2304 prepare_out = NULL;
2289 w = roundf(wf);2305 w = roundf(wf);
2290 h = roundf(hf);2306 h = roundf(hf);
2291 break;2307 break;
2292 case CUBEMAP_3_2:2308 case CUBEMAP_3_2:
2293 out_transform = cube3x2_to_xyz;2309 out_transform = cube3x2_to_xyz;
2294 err = prepare_cube_out(ctx);2310 prepare_out = prepare_cube_out;
2295 w = roundf(wf / 4.f * 3.f);2311 w = roundf(wf / 4.f * 3.f);
2296 h = roundf(hf);2312 h = roundf(hf);
2297 break;2313 break;
2298 case CUBEMAP_1_6:2314 case CUBEMAP_1_6:
2299 out_transform = cube1x6_to_xyz;2315 out_transform = cube1x6_to_xyz;
2300 err = prepare_cube_out(ctx);2316 prepare_out = prepare_cube_out;
2301 w = roundf(wf / 4.f);2317 w = roundf(wf / 4.f);
2302 h = roundf(hf * 3.f);2318 h = roundf(hf * 3.f);
2303 break;2319 break;
2304 case CUBEMAP_6_1:2320 case CUBEMAP_6_1:
2305 out_transform = cube6x1_to_xyz;2321 out_transform = cube6x1_to_xyz;
2306 err = prepare_cube_out(ctx);2322 prepare_out = prepare_cube_out;
2307 w = roundf(wf / 2.f * 3.f);2323 w = roundf(wf / 2.f * 3.f);
2308 h = roundf(hf / 2.f);2324 h = roundf(hf / 2.f);
2309 break;2325 break;
2310 case EQUIANGULAR:2326 case EQUIANGULAR:
2311 out_transform = eac_to_xyz;2327 out_transform = eac_to_xyz;
2312 err = prepare_eac_out(ctx);2328 prepare_out = prepare_eac_out;
2313 w = roundf(wf);2329 w = roundf(wf);
2314 h = roundf(hf / 8.f * 9.f);2330 h = roundf(hf / 8.f * 9.f);
2315 break;2331 break;
2316 case FLAT:2332 case FLAT:
2317 out_transform = flat_to_xyz;2333 out_transform = flat_to_xyz;
2318 err = prepare_flat_out(ctx);2334 prepare_out = prepare_flat_out;
2319 w = roundf(wf);2335 w = roundf(wf);
2320 h = roundf(hf);2336 h = roundf(hf);
2321 break;2337 break;
2322 case DUAL_FISHEYE:2338 case DUAL_FISHEYE:
2323 out_transform = dfisheye_to_xyz;2339 out_transform = dfisheye_to_xyz;
2324 err = 0;2340 prepare_out = NULL;
2325 w = roundf(wf);2341 w = roundf(wf);
2326 h = roundf(hf);2342 h = roundf(hf);
2327 break;2343 break;
2328 case BARREL:2344 case BARREL:
2329 out_transform = barrel_to_xyz;2345 out_transform = barrel_to_xyz;
2330 err = 0;2346 prepare_out = NULL;
2331 w = roundf(wf / 4.f * 5.f);2347 w = roundf(wf / 4.f * 5.f);
2332 h = roundf(hf);2348 h = roundf(hf);
2333 break;2349 break;
2334 case STEREOGRAPHIC:2350 case STEREOGRAPHIC:
2335 out_transform = stereographic_to_xyz;2351 out_transform = stereographic_to_xyz;
2336 err = prepare_stereographic_out(ctx);2352 prepare_out = prepare_stereographic_out;
2337 w = roundf(wf);2353 w = roundf(wf);
2338 h = roundf(hf * 2.f);2354 h = roundf(hf * 2.f);
2339 break;2355 break;
@@ -2342,10 +2358,6 @@ static int config_output(AVFilterLink *outlink) · 2 unmodified lines
2342 return AVERROR_BUG;2358 return AVERROR_BUG;
2343 }2359 }
2344 2360
2345 if (err != 0) {
2346 return err;
2347 }
2348
2349 // Override resolution with user values if specified2361 // Override resolution with user values if specified
2350 if (s->width > 0 && s->height > 0) {2362 if (s->width > 0 && s->height > 0) {
2351 w = s->width;2363 w = s->width;
@@ -2361,6 +2373,15 @@ static int config_output(AVFilterLink *outlink) · 9 unmodified lines
2361 FFSWAP(int, w, h);2373 FFSWAP(int, w, h);
2362 }2374 }
2363 2375
2376 if (s->d_fov > 0.f)
2377 fov_from_dfov(s, w, h);
2378
2379 if (prepare_out) {
2380 err = prepare_out(ctx);
2381 if (err != 0)
2382 return err;
2383 }
2384
2364 s->planeheight[1] = s->planeheight[2] = FF_CEIL_RSHIFT(h, desc->log2_chroma_h);2385 s->planeheight[1] = s->planeheight[2] = FF_CEIL_RSHIFT(h, desc->log2_chroma_h);
2365 s->planeheight[0] = s->planeheight[3] = h;2386 s->planeheight[0] = s->planeheight[3] = h;
2366 s->planewidth[1] = s->planewidth[2] = FF_CEIL_RSHIFT(w, desc->log2_chroma_w);2387 s->planewidth[1] = s->planewidth[2] = FF_CEIL_RSHIFT(w, desc->log2_chroma_w);

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