History

avfilter/vf_v360: add perspective output projection

Paul B Mahol committed 6 years ago

Commit fdddc0d1 parent 6ae84e73 files · +63 −0Browse files

Unified · Split

3 files
  1. doc/filters.texi +9 −0
  2. libavfilter/v360.h +1 −0
  3. libavfilter/vf_v360.c +53 −0
doc/filters.texi+9−0
@@ -19003,6 +19003,15 @@ Set horizontal/vertical/diagonal field of view. Values in degrees. · 19002 unmodified lines
1900319003 If diagonal field of view is set it overrides horizontal and vertical field of view.
1900419004 @end table
1900519005
19006+@item perspective
19007+Perspective projection. @i{(output only)}
19008+
19009+Format specific options:
19010+@table @option
19011+@item v_fov
19012+Set perspective parameter.
19013+@end table
19014+
1900619015 @end table
1900719016
1900819017 @item interp
libavfilter/v360.h+1−0
@@ -46,6 +46,7 @@ enum Projections { · 45 unmodified lines
4646 FISHEYE,
4747 PANNINI,
4848 CYLINDRICAL,
49+ PERSPECTIVE,
4950 NB_PROJECTIONS,
5051 };
5152
libavfilter/vf_v360.c+53−0
@@ -90,6 +90,7 @@ static const AVOption v360_options[] = { · 89 unmodified lines
9090 { "fisheye", "fisheye", 0, AV_OPT_TYPE_CONST, {.i64=FISHEYE}, 0, 0, FLAGS, "out" },
9191 { "pannini", "pannini", 0, AV_OPT_TYPE_CONST, {.i64=PANNINI}, 0, 0, FLAGS, "out" },
9292 {"cylindrical", "cylindrical", 0, AV_OPT_TYPE_CONST, {.i64=CYLINDRICAL}, 0, 0, FLAGS, "out" },
93+ {"perspective", "perspective", 0, AV_OPT_TYPE_CONST, {.i64=PERSPECTIVE}, 0, 0, FLAGS, "out" },
9394 { "interp", "set interpolation method", OFFSET(interp), AV_OPT_TYPE_INT, {.i64=BILINEAR}, 0, NB_INTERP_METHODS-1, FLAGS, "interp" },
9495 { "near", "nearest neighbour", 0, AV_OPT_TYPE_CONST, {.i64=NEAREST}, 0, 0, FLAGS, "interp" },
9596 { "nearest", "nearest neighbour", 0, AV_OPT_TYPE_CONST, {.i64=NEAREST}, 0, 0, FLAGS, "interp" },
@@ -2334,6 +2335,51 @@ static void cylindrical_to_xyz(const V360Context *s, · 2238 unmodified lines
23342335 normalize_vector(vec);
23352336 }
23362337
2338+/**
2339+ * Calculate 3D coordinates on sphere for corresponding frame position in perspective format.
2340+ *
2341+ * @param s filter private context
2342+ * @param i horizontal position on frame [0, width)
2343+ * @param j vertical position on frame [0, height)
2344+ * @param width frame width
2345+ * @param height frame height
2346+ * @param vec coordinates on sphere
2347+ */
2348+static void perspective_to_xyz(const V360Context *s,
2349+ int i, int j, int width, int height,
2350+ float *vec)
2351+{
2352+ const float uf = ((2.f * i) / width - 1.f);
2353+ const float vf = ((2.f * j) / height - 1.f);
2354+ const float rh = hypotf(uf, vf);
2355+ const float sinzz = 1.f - rh * rh;
2356+ const float h = 1.f + s->v_fov;
2357+ const float sinz = (h - sqrtf(sinzz)) / (h / rh + rh / h);
2358+ const float sinz2 = sinz * sinz;
2359+
2360+ if (sinz2 <= 1.f) {
2361+ const float cosz = sqrtf(1.f - sinz2);
2362+
2363+ const float theta = asinf(cosz);
2364+ const float phi = atan2f(uf, vf);
2365+
2366+ const float sin_phi = sinf(phi);
2367+ const float cos_phi = cosf(phi);
2368+ const float sin_theta = sinf(theta);
2369+ const float cos_theta = cosf(theta);
2370+
2371+ vec[0] = cos_theta * sin_phi;
2372+ vec[1] = sin_theta;
2373+ vec[2] = -cos_theta * cos_phi;
2374+ } else {
2375+ vec[0] = 0.f;
2376+ vec[1] = -1.f;
2377+ vec[2] = 0.f;
2378+ }
2379+
2380+ normalize_vector(vec);
2381+}
2382+
23372383 /**
23382384 * Calculate 3D coordinates on sphere for corresponding frame position in dual fisheye format.
23392385 *
@@ -2884,6 +2930,7 @@ static int config_output(AVFilterLink *outlink) · 544 unmodified lines
28842930 wf = w;
28852931 hf = h / 9.f * 8.f;
28862932 break;
2933+ case PERSPECTIVE:
28872934 case CYLINDRICAL:
28882935 case PANNINI:
28892936 case FISHEYE:
@@ -3038,6 +3085,12 @@ static int config_output(AVFilterLink *outlink) · 148 unmodified lines
30383085 w = roundf(wf);
30393086 h = roundf(hf * 0.5f);
30403087 break;
3088+ case PERSPECTIVE:
3089+ s->out_transform = perspective_to_xyz;
3090+ prepare_out = NULL;
3091+ w = roundf(wf / 2.f);
3092+ h = roundf(hf);
3093+ break;
30413094 default:
30423095 av_log(ctx, AV_LOG_ERROR, "Specified output format is not handled.\n");
30433096 return AVERROR_BUG;

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