History

avfilter/vf_v360: add support for cylindrical input format

Paul B Mahol committed 6 years ago

Commit 19f75e71 parent e57b9aa2 files · +72 −1Browse files

Unified · Split

2 files
  1. doc/filters.texi +7 −0
  2. libavfilter/vf_v360.c +65 −1
doc/filters.texi+7−0
@@ -19010,6 +19010,13 @@ Format specific options: · 19009 unmodified lines
1901019010 @item d_fov
1901119011 Set horizontal/vertical/diagonal field of view. Values in degrees.
1901219012
19013+If diagonal field of view is set it overrides horizontal and vertical field of view.
19014+
19015+@item ih_fov
19016+@item iv_fov
19017+@item id_fov
19018+Set input horizontal/vertical/diagonal field of view. Values in degrees.
19019+
1901319020 If diagonal field of view is set it overrides horizontal and vertical field of view.
1901419021 @end table
1901519022
libavfilter/vf_v360.c+65−1
@@ -72,6 +72,7 @@ static const AVOption v360_options[] = { · 71 unmodified lines
7272 { "ball", "ball", 0, AV_OPT_TYPE_CONST, {.i64=BALL}, 0, 0, FLAGS, "in" },
7373 { "hammer", "hammer", 0, AV_OPT_TYPE_CONST, {.i64=HAMMER}, 0, 0, FLAGS, "in" },
7474 {"sinusoidal", "sinusoidal", 0, AV_OPT_TYPE_CONST, {.i64=SINUSOIDAL}, 0, 0, FLAGS, "in" },
75+ {"cylindrical", "cylindrical", 0, AV_OPT_TYPE_CONST, {.i64=CYLINDRICAL}, 0, 0, FLAGS, "in" },
7576 { "output", "set output projection", OFFSET(out), AV_OPT_TYPE_INT, {.i64=CUBEMAP_3_2}, 0, NB_PROJECTIONS-1, FLAGS, "out" },
7677 { "e", "equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=EQUIRECTANGULAR}, 0, 0, FLAGS, "out" },
7778 { "equirect", "equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=EQUIRECTANGULAR}, 0, 0, FLAGS, "out" },
@@ -2406,6 +2407,64 @@ static void cylindrical_to_xyz(const V360Context *s, · 2328 unmodified lines
24062407 normalize_vector(vec);
24072408 }
24082409
2410+/**
2411+ * Prepare data for processing cylindrical input format.
2412+ *
2413+ * @param ctx filter context
2414+ *
2415+ * @return error code
2416+ */
2417+static int prepare_cylindrical_in(AVFilterContext *ctx)
2418+{
2419+ V360Context *s = ctx->priv;
2420+
2421+ s->iflat_range[0] = M_PI * s->ih_fov / 360.f;
2422+ s->iflat_range[1] = tanf(0.5f * s->iv_fov * M_PI / 180.f);
2423+
2424+ return 0;
2425+}
2426+
2427+/**
2428+ * Calculate frame position in cylindrical format for corresponding 3D coordinates on sphere.
2429+ *
2430+ * @param s filter private context
2431+ * @param vec coordinates on sphere
2432+ * @param width frame width
2433+ * @param height frame height
2434+ * @param us horizontal coordinates for interpolation window
2435+ * @param vs vertical coordinates for interpolation window
2436+ * @param du horizontal relative coordinate
2437+ * @param dv vertical relative coordinate
2438+ */
2439+static void xyz_to_cylindrical(const V360Context *s,
2440+ const float *vec, int width, int height,
2441+ int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
2442+{
2443+ const float phi = atan2f(vec[0], -vec[2]) * s->input_mirror_modifier[0] / s->iflat_range[0];
2444+ const float theta = atan2f(-vec[1], hypotf(vec[0], vec[2])) * s->input_mirror_modifier[1] / s->iflat_range[1];
2445+ int visible, ui, vi;
2446+ float uf, vf;
2447+
2448+ uf = (phi + 1.f) * (width - 1) / 2.f;
2449+ vf = (tanf(theta) + 1.f) * height / 2.f;
2450+ ui = floorf(uf);
2451+ vi = floorf(vf);
2452+
2453+ visible = vi >= 0 && vi < height && ui >= 0 && ui < width &&
2454+ theta <= M_PI * s->iv_fov / 180.f &&
2455+ theta >= -M_PI * s->iv_fov / 180.f;
2456+
2457+ *du = uf - ui;
2458+ *dv = vf - vi;
2459+
2460+ for (int i = -1; i < 3; i++) {
2461+ for (int j = -1; j < 3; j++) {
2462+ us[i + 1][j + 1] = visible ? av_clip(ui + j, 0, width - 1) : 0;
2463+ vs[i + 1][j + 1] = visible ? av_clip(vi + i, 0, height - 1) : 0;
2464+ }
2465+ }
2466+}
2467+
24092468 /**
24102469 * Calculate 3D coordinates on sphere for corresponding frame position in perspective format.
24112470 *
@@ -3011,7 +3070,6 @@ static int config_output(AVFilterLink *outlink) · 599 unmodified lines
30113070 hf = h;
30123071 break;
30133072 case PERSPECTIVE:
3014− case CYLINDRICAL:
30153073 case PANNINI:
30163074 case FISHEYE:
30173075 av_log(ctx, AV_LOG_ERROR, "Supplied format is not accepted as input.\n");
@@ -3058,6 +3116,12 @@ static int config_output(AVFilterLink *outlink) · 40 unmodified lines
30583116 wf = w;
30593117 hf = h;
30603118 break;
3119+ case CYLINDRICAL:
3120+ s->in_transform = xyz_to_cylindrical;
3121+ err = prepare_cylindrical_in(ctx);
3122+ wf = w;
3123+ hf = h * 2.f;
3124+ break;
30613125 default:
30623126 av_log(ctx, AV_LOG_ERROR, "Specified input format is not handled.\n");
30633127 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