History

avfilter/vf_v360: implement diagonal field of view

Paul B Mahol committed 7 years ago

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

Showing the changes to libavfilter (2 of 3 files). Show all

Unified · Split

2 files
  1. libavfilter/v360.h +1 −1
  2. libavfilter/vf_v360.c +34 −13
libavfilter/v360.h+1−1
@@ -103,7 +103,7 @@ typedef struct V360Context { · 102 unmodified lines
103103 int h_flip, v_flip, d_flip;
104104 int in_transpose, out_transpose;
105105
106− float h_fov, v_fov;
106+ float h_fov, v_fov, d_fov;
107107 float flat_range[3];
108108
109109 float input_mirror_modifier[2];
libavfilter/vf_v360.c+34−13
@@ -102,6 +102,7 @@ static const AVOption v360_options[] = { · 101 unmodified lines
102102 { "rorder", "rotation order", OFFSET(rorder), AV_OPT_TYPE_STRING, {.str="ypr"}, 0, 0, FLAGS, "rorder"},
103103 { "h_fov", "horizontal field of view", OFFSET(h_fov), AV_OPT_TYPE_FLOAT, {.dbl=90.f}, 0.00001f, 360.f, FLAGS, "h_fov"},
104104 { "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"},
105106 { "h_flip", "flip out video horizontally", OFFSET(h_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "h_flip"},
106107 { "v_flip", "flip out video vertically", OFFSET(v_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "v_flip"},
107108 { "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
21392140 return 0;
21402141 }
21412142
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+
21422157 static int config_output(AVFilterLink *outlink)
21432158 {
21442159 AVFilterContext *ctx = outlink->src;
@@ -2161,6 +2176,7 @@ static int config_output(AVFilterLink *outlink) · 16 unmodified lines
21612176 float *vec);
21622177 void (*calculate_kernel)(float du, float dv, const XYRemap *r_tmp,
21632178 uint16_t *u, uint16_t *v, int16_t *ker);
2179+ int (*prepare_out)(AVFilterContext *ctx);
21642180 float rot_mat[3][3];
21652181
21662182 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
22852301 switch (s->out) {
22862302 case EQUIRECTANGULAR:
22872303 out_transform = equirect_to_xyz;
2288− err = 0;
2304+ prepare_out = NULL;
22892305 w = roundf(wf);
22902306 h = roundf(hf);
22912307 break;
22922308 case CUBEMAP_3_2:
22932309 out_transform = cube3x2_to_xyz;
2294− err = prepare_cube_out(ctx);
2310+ prepare_out = prepare_cube_out;
22952311 w = roundf(wf / 4.f * 3.f);
22962312 h = roundf(hf);
22972313 break;
22982314 case CUBEMAP_1_6:
22992315 out_transform = cube1x6_to_xyz;
2300− err = prepare_cube_out(ctx);
2316+ prepare_out = prepare_cube_out;
23012317 w = roundf(wf / 4.f);
23022318 h = roundf(hf * 3.f);
23032319 break;
23042320 case CUBEMAP_6_1:
23052321 out_transform = cube6x1_to_xyz;
2306− err = prepare_cube_out(ctx);
2322+ prepare_out = prepare_cube_out;
23072323 w = roundf(wf / 2.f * 3.f);
23082324 h = roundf(hf / 2.f);
23092325 break;
23102326 case EQUIANGULAR:
23112327 out_transform = eac_to_xyz;
2312− err = prepare_eac_out(ctx);
2328+ prepare_out = prepare_eac_out;
23132329 w = roundf(wf);
23142330 h = roundf(hf / 8.f * 9.f);
23152331 break;
23162332 case FLAT:
23172333 out_transform = flat_to_xyz;
2318− err = prepare_flat_out(ctx);
2334+ prepare_out = prepare_flat_out;
23192335 w = roundf(wf);
23202336 h = roundf(hf);
23212337 break;
23222338 case DUAL_FISHEYE:
23232339 out_transform = dfisheye_to_xyz;
2324− err = 0;
2340+ prepare_out = NULL;
23252341 w = roundf(wf);
23262342 h = roundf(hf);
23272343 break;
23282344 case BARREL:
23292345 out_transform = barrel_to_xyz;
2330− err = 0;
2346+ prepare_out = NULL;
23312347 w = roundf(wf / 4.f * 5.f);
23322348 h = roundf(hf);
23332349 break;
23342350 case STEREOGRAPHIC:
23352351 out_transform = stereographic_to_xyz;
2336− err = prepare_stereographic_out(ctx);
2352+ prepare_out = prepare_stereographic_out;
23372353 w = roundf(wf);
23382354 h = roundf(hf * 2.f);
23392355 break;
@@ -2342,10 +2358,6 @@ static int config_output(AVFilterLink *outlink) · 2 unmodified lines
23422358 return AVERROR_BUG;
23432359 }
23442360
2345− if (err != 0) {
2346− return err;
2347− }
2348−
23492361 // Override resolution with user values if specified
23502362 if (s->width > 0 && s->height > 0) {
23512363 w = s->width;
@@ -2361,6 +2373,15 @@ static int config_output(AVFilterLink *outlink) · 9 unmodified lines
23612373 FFSWAP(int, w, h);
23622374 }
23632375
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+
23642385 s->planeheight[1] = s->planeheight[2] = FF_CEIL_RSHIFT(h, desc->log2_chroma_h);
23652386 s->planeheight[0] = s->planeheight[3] = h;
23662387 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