History

avfilter/vf_v360: add perspective output projection

Paul B Mahol committed 6 years ago

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

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

Unified · Split

2 files
  1. libavfilter/v360.h +1 −0
  2. libavfilter/vf_v360.c +53 −0
libavfilter/v360.h+1−0
@@ -46,6 +46,7 @@ enum Projections { · 45 unmodified lines
46 FISHEYE,46 FISHEYE,
47 PANNINI,47 PANNINI,
48 CYLINDRICAL,48 CYLINDRICAL,
49 PERSPECTIVE,
49 NB_PROJECTIONS,50 NB_PROJECTIONS,
50};51};
51 52
libavfilter/vf_v360.c+53−0
@@ -90,6 +90,7 @@ static const AVOption v360_options[] = { · 89 unmodified lines
90 { "fisheye", "fisheye", 0, AV_OPT_TYPE_CONST, {.i64=FISHEYE}, 0, 0, FLAGS, "out" },90 { "fisheye", "fisheye", 0, AV_OPT_TYPE_CONST, {.i64=FISHEYE}, 0, 0, FLAGS, "out" },
91 { "pannini", "pannini", 0, AV_OPT_TYPE_CONST, {.i64=PANNINI}, 0, 0, FLAGS, "out" },91 { "pannini", "pannini", 0, AV_OPT_TYPE_CONST, {.i64=PANNINI}, 0, 0, FLAGS, "out" },
92 {"cylindrical", "cylindrical", 0, AV_OPT_TYPE_CONST, {.i64=CYLINDRICAL}, 0, 0, FLAGS, "out" },92 {"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" },
93 { "interp", "set interpolation method", OFFSET(interp), AV_OPT_TYPE_INT, {.i64=BILINEAR}, 0, NB_INTERP_METHODS-1, FLAGS, "interp" },94 { "interp", "set interpolation method", OFFSET(interp), AV_OPT_TYPE_INT, {.i64=BILINEAR}, 0, NB_INTERP_METHODS-1, FLAGS, "interp" },
94 { "near", "nearest neighbour", 0, AV_OPT_TYPE_CONST, {.i64=NEAREST}, 0, 0, FLAGS, "interp" },95 { "near", "nearest neighbour", 0, AV_OPT_TYPE_CONST, {.i64=NEAREST}, 0, 0, FLAGS, "interp" },
95 { "nearest", "nearest neighbour", 0, AV_OPT_TYPE_CONST, {.i64=NEAREST}, 0, 0, FLAGS, "interp" },96 { "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
2334 normalize_vector(vec);2335 normalize_vector(vec);
2335}2336}
2336 2337
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 */
2348static 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
2337/**2383/**
2338 * Calculate 3D coordinates on sphere for corresponding frame position in dual fisheye format.2384 * Calculate 3D coordinates on sphere for corresponding frame position in dual fisheye format.
2339 *2385 *
@@ -2884,6 +2930,7 @@ static int config_output(AVFilterLink *outlink) · 544 unmodified lines
2884 wf = w;2930 wf = w;
2885 hf = h / 9.f * 8.f;2931 hf = h / 9.f * 8.f;
2886 break;2932 break;
2933 case PERSPECTIVE:
2887 case CYLINDRICAL:2934 case CYLINDRICAL:
2888 case PANNINI:2935 case PANNINI:
2889 case FISHEYE:2936 case FISHEYE:
@@ -3038,6 +3085,12 @@ static int config_output(AVFilterLink *outlink) · 148 unmodified lines
3038 w = roundf(wf);3085 w = roundf(wf);
3039 h = roundf(hf * 0.5f);3086 h = roundf(hf * 0.5f);
3040 break;3087 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;
3041 default:3094 default:
3042 av_log(ctx, AV_LOG_ERROR, "Specified output format is not handled.\n");3095 av_log(ctx, AV_LOG_ERROR, "Specified output format is not handled.\n");
3043 return AVERROR_BUG;3096 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