| @@ -102,6 +102,7 @@ static const AVOption v360_options[] = { · 101 unmodified lines |
| 102 | 102 | { "rorder", "rotation order", OFFSET(rorder), AV_OPT_TYPE_STRING, {.str="ypr"}, 0, 0, FLAGS, "rorder"}, |
| 103 | 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 | 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 | 106 | { "h_flip", "flip out video horizontally", OFFSET(h_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "h_flip"}, |
| 106 | 107 | { "v_flip", "flip out video vertically", OFFSET(v_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "v_flip"}, |
| 107 | 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 | 2140 | return 0; |
| 2140 | 2141 | } |
| 2141 | 2142 | |
| 2143 | +static 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 | + |
| 2142 | 2157 | static int config_output(AVFilterLink *outlink) |
| 2143 | 2158 | { |
| 2144 | 2159 | AVFilterContext *ctx = outlink->src; |
| @@ -2161,6 +2176,7 @@ static int config_output(AVFilterLink *outlink) · 16 unmodified lines |
| 2161 | 2176 | float *vec); |
| 2162 | 2177 | void (*calculate_kernel)(float du, float dv, const XYRemap *r_tmp, |
| 2163 | 2178 | uint16_t *u, uint16_t *v, int16_t *ker); |
| 2179 | + int (*prepare_out)(AVFilterContext *ctx); |
| 2164 | 2180 | float rot_mat[3][3]; |
| 2165 | 2181 | |
| 2166 | 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 | 2301 | switch (s->out) { |
| 2286 | 2302 | case EQUIRECTANGULAR: |
| 2287 | 2303 | out_transform = equirect_to_xyz; |
| 2288 | | − err = 0; |
| 2304 | + prepare_out = NULL; |
| 2289 | 2305 | w = roundf(wf); |
| 2290 | 2306 | h = roundf(hf); |
| 2291 | 2307 | break; |
| 2292 | 2308 | case CUBEMAP_3_2: |
| 2293 | 2309 | out_transform = cube3x2_to_xyz; |
| 2294 | | − err = prepare_cube_out(ctx); |
| 2310 | + prepare_out = prepare_cube_out; |
| 2295 | 2311 | w = roundf(wf / 4.f * 3.f); |
| 2296 | 2312 | h = roundf(hf); |
| 2297 | 2313 | break; |
| 2298 | 2314 | case CUBEMAP_1_6: |
| 2299 | 2315 | out_transform = cube1x6_to_xyz; |
| 2300 | | − err = prepare_cube_out(ctx); |
| 2316 | + prepare_out = prepare_cube_out; |
| 2301 | 2317 | w = roundf(wf / 4.f); |
| 2302 | 2318 | h = roundf(hf * 3.f); |
| 2303 | 2319 | break; |
| 2304 | 2320 | case CUBEMAP_6_1: |
| 2305 | 2321 | out_transform = cube6x1_to_xyz; |
| 2306 | | − err = prepare_cube_out(ctx); |
| 2322 | + prepare_out = prepare_cube_out; |
| 2307 | 2323 | w = roundf(wf / 2.f * 3.f); |
| 2308 | 2324 | h = roundf(hf / 2.f); |
| 2309 | 2325 | break; |
| 2310 | 2326 | case EQUIANGULAR: |
| 2311 | 2327 | out_transform = eac_to_xyz; |
| 2312 | | − err = prepare_eac_out(ctx); |
| 2328 | + prepare_out = prepare_eac_out; |
| 2313 | 2329 | w = roundf(wf); |
| 2314 | 2330 | h = roundf(hf / 8.f * 9.f); |
| 2315 | 2331 | break; |
| 2316 | 2332 | case FLAT: |
| 2317 | 2333 | out_transform = flat_to_xyz; |
| 2318 | | − err = prepare_flat_out(ctx); |
| 2334 | + prepare_out = prepare_flat_out; |
| 2319 | 2335 | w = roundf(wf); |
| 2320 | 2336 | h = roundf(hf); |
| 2321 | 2337 | break; |
| 2322 | 2338 | case DUAL_FISHEYE: |
| 2323 | 2339 | out_transform = dfisheye_to_xyz; |
| 2324 | | − err = 0; |
| 2340 | + prepare_out = NULL; |
| 2325 | 2341 | w = roundf(wf); |
| 2326 | 2342 | h = roundf(hf); |
| 2327 | 2343 | break; |
| 2328 | 2344 | case BARREL: |
| 2329 | 2345 | out_transform = barrel_to_xyz; |
| 2330 | | − err = 0; |
| 2346 | + prepare_out = NULL; |
| 2331 | 2347 | w = roundf(wf / 4.f * 5.f); |
| 2332 | 2348 | h = roundf(hf); |
| 2333 | 2349 | break; |
| 2334 | 2350 | case STEREOGRAPHIC: |
| 2335 | 2351 | out_transform = stereographic_to_xyz; |
| 2336 | | − err = prepare_stereographic_out(ctx); |
| 2352 | + prepare_out = prepare_stereographic_out; |
| 2337 | 2353 | w = roundf(wf); |
| 2338 | 2354 | h = roundf(hf * 2.f); |
| 2339 | 2355 | break; |
| @@ -2342,10 +2358,6 @@ static int config_output(AVFilterLink *outlink) · 2 unmodified lines |
| 2342 | 2358 | return AVERROR_BUG; |
| 2343 | 2359 | } |
| 2344 | 2360 | |
| 2345 | | − if (err != 0) { |
| 2346 | | − return err; |
| 2347 | | − } |
| 2348 | | − |
| 2349 | 2361 | // Override resolution with user values if specified |
| 2350 | 2362 | if (s->width > 0 && s->height > 0) { |
| 2351 | 2363 | w = s->width; |
| @@ -2361,6 +2373,15 @@ static int config_output(AVFilterLink *outlink) · 9 unmodified lines |
| 2361 | 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 | 2385 | s->planeheight[1] = s->planeheight[2] = FF_CEIL_RSHIFT(h, desc->log2_chroma_h); |
| 2365 | 2386 | s->planeheight[0] = s->planeheight[3] = h; |
| 2366 | 2387 | s->planewidth[1] = s->planewidth[2] = FF_CEIL_RSHIFT(w, desc->log2_chroma_w); |