History

avfilter/vf_v360: add options to h/w unflip input video

Paul B Mahol committed 7 years ago

Commit 5b12a471 parent a06d7033 files · +73 −27Browse files

Unified · Split

3 files
  1. doc/filters.texi +4 −0
  2. libavfilter/v360.h +3 −0
  3. libavfilter/vf_v360.c +66 −27
doc/filters.texi+4−0
@@ -18084,6 +18084,10 @@ Default value is @b{@samp{ypr}}. · 18083 unmodified lines
18084@item d_flip18084@item d_flip
18085Flip the output video horizontally/vertically/in-depth. Boolean values.18085Flip the output video horizontally/vertically/in-depth. Boolean values.
18086 18086
18087@item ih_flip
18088@item iv_flip
18089Set if input video is flipped horizontally/vertically. Boolean values.
18090
18087@item in_trans18091@item in_trans
18088Set if input video is transposed. Boolean value, by default disabled.18092Set if input video is transposed. Boolean value, by default disabled.
18089 18093
libavfilter/v360.h+3−0
@@ -98,12 +98,15 @@ typedef struct V360Context { · 97 unmodified lines
98 98
99 float yaw, pitch, roll;99 float yaw, pitch, roll;
100 100
101 int ih_flip, iv_flip;
101 int h_flip, v_flip, d_flip;102 int h_flip, v_flip, d_flip;
102 int in_transpose, out_transpose;103 int in_transpose, out_transpose;
103 104
104 float h_fov, v_fov;105 float h_fov, v_fov;
105 float flat_range[3];106 float flat_range[3];
106 107
108 float input_mirror_modifier[2];
109
107 int planewidth[4], planeheight[4];110 int planewidth[4], planeheight[4];
108 int inplanewidth[4], inplaneheight[4];111 int inplanewidth[4], inplaneheight[4];
109 int nb_planes;112 int nb_planes;
libavfilter/vf_v360.c+66−27
@@ -96,6 +96,8 @@ static const AVOption v360_options[] = { · 95 unmodified lines
96 { "h_flip", "flip out video horizontally", OFFSET(h_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "h_flip"},96 { "h_flip", "flip out video horizontally", OFFSET(h_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "h_flip"},
97 { "v_flip", "flip out video vertically", OFFSET(v_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "v_flip"},97 { "v_flip", "flip out video vertically", OFFSET(v_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "v_flip"},
98 { "d_flip", "flip out video indepth", OFFSET(d_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "d_flip"},98 { "d_flip", "flip out video indepth", OFFSET(d_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "d_flip"},
99 { "ih_flip", "flip in video horizontally", OFFSET(ih_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "ih_flip"},
100 { "iv_flip", "flip in video vertically", OFFSET(iv_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "iv_flip"},
99 { "in_trans", "transpose video input", OFFSET(in_transpose), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "in_transpose"},101 { "in_trans", "transpose video input", OFFSET(in_transpose), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "in_transpose"},
100 { "out_trans", "transpose video output", OFFSET(out_transpose), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "out_transpose"},102 { "out_trans", "transpose video output", OFFSET(out_transpose), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "out_transpose"},
101 { NULL }103 { NULL }
@@ -815,6 +817,9 @@ static void xyz_to_cube(const V360Context *s, · 713 unmodified lines
815 817
816 face = s->in_cubemap_face_order[*direction];818 face = s->in_cubemap_face_order[*direction];
817 rotate_cube_face(uf, vf, s->in_cubemap_face_rotation[face]);819 rotate_cube_face(uf, vf, s->in_cubemap_face_rotation[face]);
820
821 (*uf) *= s->input_mirror_modifier[0];
822 (*vf) *= s->input_mirror_modifier[1];
818}823}
819 824
820/**825/**
@@ -1125,7 +1130,6 @@ static void xyz_to_cube3x2(const V360Context *s, · 304 unmodified lines
1125 new_vi = av_clip(roundf(0.5f * new_ehi * (vf + 1.f)), 0, new_ehi - 1);1130 new_vi = av_clip(roundf(0.5f * new_ehi * (vf + 1.f)), 0, new_ehi - 1);
1126 }1131 }
1127 1132
1128
1129 us[i + 1][j + 1] = u_shift + new_ui;1133 us[i + 1][j + 1] = u_shift + new_ui;
1130 vs[i + 1][j + 1] = v_shift + new_vi;1134 vs[i + 1][j + 1] = v_shift + new_vi;
1131 }1135 }
@@ -1259,7 +1263,6 @@ static void xyz_to_cube1x6(const V360Context *s, · 127 unmodified lines
1259 new_vi = av_clip(roundf(0.5f * new_ehi * (vf + 1.f)), 0, new_ehi - 1);1263 new_vi = av_clip(roundf(0.5f * new_ehi * (vf + 1.f)), 0, new_ehi - 1);
1260 }1264 }
1261 1265
1262
1263 us[i + 1][j + 1] = new_ui;1266 us[i + 1][j + 1] = new_ui;
1264 vs[i + 1][j + 1] = v_shift + new_vi;1267 vs[i + 1][j + 1] = v_shift + new_vi;
1265 }1268 }
@@ -1337,7 +1340,6 @@ static void xyz_to_cube6x1(const V360Context *s, · 71 unmodified lines
1337 new_vi = av_clip(roundf(0.5f * ehi * (vf + 1.f)), 0, ehi - 1);1340 new_vi = av_clip(roundf(0.5f * ehi * (vf + 1.f)), 0, ehi - 1);
1338 }1341 }
1339 1342
1340
1341 us[i + 1][j + 1] = u_shift + new_ui;1343 us[i + 1][j + 1] = u_shift + new_ui;
1342 vs[i + 1][j + 1] = new_vi;1344 vs[i + 1][j + 1] = new_vi;
1343 }1345 }
@@ -1387,8 +1389,8 @@ static void xyz_to_equirect(const V360Context *s, · 43 unmodified lines
1387 const float *vec, int width, int height,1389 const float *vec, int width, int height,
1388 uint16_t us[4][4], uint16_t vs[4][4], float *du, float *dv)1390 uint16_t us[4][4], uint16_t vs[4][4], float *du, float *dv)
1389{1391{
1390 const float phi = atan2f(vec[0], -vec[2]);1392 const float phi = atan2f(vec[0], -vec[2]) * s->input_mirror_modifier[0];
1391 const float theta = asinf(-vec[1]);1393 const float theta = asinf(-vec[1]) * s->input_mirror_modifier[1];
1392 float uf, vf;1394 float uf, vf;
1393 int ui, vi;1395 int ui, vi;
1394 int i, j;1396 int i, j;
@@ -1420,19 +1422,51 @@ static int prepare_eac_in(AVFilterContext *ctx) · 25 unmodified lines
1420{1422{
1421 V360Context *s = ctx->priv;1423 V360Context *s = ctx->priv;
1422 1424
1423 s->in_cubemap_face_order[RIGHT] = TOP_RIGHT;1425 if (s->ih_flip && s->iv_flip) {
1424 s->in_cubemap_face_order[LEFT] = TOP_LEFT;1426 s->in_cubemap_face_order[RIGHT] = BOTTOM_LEFT;
1425 s->in_cubemap_face_order[UP] = BOTTOM_RIGHT;1427 s->in_cubemap_face_order[LEFT] = BOTTOM_RIGHT;
1426 s->in_cubemap_face_order[DOWN] = BOTTOM_LEFT;1428 s->in_cubemap_face_order[UP] = TOP_LEFT;
1427 s->in_cubemap_face_order[FRONT] = TOP_MIDDLE;1429 s->in_cubemap_face_order[DOWN] = TOP_RIGHT;
1428 s->in_cubemap_face_order[BACK] = BOTTOM_MIDDLE;1430 s->in_cubemap_face_order[FRONT] = BOTTOM_MIDDLE;
1431 s->in_cubemap_face_order[BACK] = TOP_MIDDLE;
1432 } else if (s->ih_flip) {
1433 s->in_cubemap_face_order[RIGHT] = TOP_LEFT;
1434 s->in_cubemap_face_order[LEFT] = TOP_RIGHT;
1435 s->in_cubemap_face_order[UP] = BOTTOM_LEFT;
1436 s->in_cubemap_face_order[DOWN] = BOTTOM_RIGHT;
1437 s->in_cubemap_face_order[FRONT] = TOP_MIDDLE;
1438 s->in_cubemap_face_order[BACK] = BOTTOM_MIDDLE;
1439 } else if (s->iv_flip) {
1440 s->in_cubemap_face_order[RIGHT] = BOTTOM_RIGHT;
1441 s->in_cubemap_face_order[LEFT] = BOTTOM_LEFT;
1442 s->in_cubemap_face_order[UP] = TOP_RIGHT;
1443 s->in_cubemap_face_order[DOWN] = TOP_LEFT;
1444 s->in_cubemap_face_order[FRONT] = BOTTOM_MIDDLE;
1445 s->in_cubemap_face_order[BACK] = TOP_MIDDLE;
1446 } else {
1447 s->in_cubemap_face_order[RIGHT] = TOP_RIGHT;
1448 s->in_cubemap_face_order[LEFT] = TOP_LEFT;
1449 s->in_cubemap_face_order[UP] = BOTTOM_RIGHT;
1450 s->in_cubemap_face_order[DOWN] = BOTTOM_LEFT;
1451 s->in_cubemap_face_order[FRONT] = TOP_MIDDLE;
1452 s->in_cubemap_face_order[BACK] = BOTTOM_MIDDLE;
1453 }
1429 1454
1430 s->in_cubemap_face_rotation[TOP_LEFT] = ROT_0;1455 if (s->iv_flip) {
1431 s->in_cubemap_face_rotation[TOP_MIDDLE] = ROT_0;1456 s->in_cubemap_face_rotation[TOP_LEFT] = ROT_270;
1432 s->in_cubemap_face_rotation[TOP_RIGHT] = ROT_0;1457 s->in_cubemap_face_rotation[TOP_MIDDLE] = ROT_90;
1433 s->in_cubemap_face_rotation[BOTTOM_LEFT] = ROT_270;1458 s->in_cubemap_face_rotation[TOP_RIGHT] = ROT_270;
1434 s->in_cubemap_face_rotation[BOTTOM_MIDDLE] = ROT_90;1459 s->in_cubemap_face_rotation[BOTTOM_LEFT] = ROT_0;
1435 s->in_cubemap_face_rotation[BOTTOM_RIGHT] = ROT_270;1460 s->in_cubemap_face_rotation[BOTTOM_MIDDLE] = ROT_0;
1461 s->in_cubemap_face_rotation[BOTTOM_RIGHT] = ROT_0;
1462 } else {
1463 s->in_cubemap_face_rotation[TOP_LEFT] = ROT_0;
1464 s->in_cubemap_face_rotation[TOP_MIDDLE] = ROT_0;
1465 s->in_cubemap_face_rotation[TOP_RIGHT] = ROT_0;
1466 s->in_cubemap_face_rotation[BOTTOM_LEFT] = ROT_270;
1467 s->in_cubemap_face_rotation[BOTTOM_MIDDLE] = ROT_90;
1468 s->in_cubemap_face_rotation[BOTTOM_RIGHT] = ROT_270;
1469 }
1436 1470
1437 return 0;1471 return 0;
1438}1472}
@@ -1694,8 +1728,8 @@ static void xyz_to_dfisheye(const V360Context *s, · 255 unmodified lines
1694 const float ew = width / 2.f;1728 const float ew = width / 2.f;
1695 const float eh = height;1729 const float eh = height;
1696 1730
1697 const float phi = atan2f(-vec[1], -vec[0]);1731 const float phi = atan2f(-vec[1], -vec[0]) * s->input_mirror_modifier[0];
1698 const float theta = acosf(fabsf(vec[2])) / M_PI;1732 const float theta = acosf(fabsf(vec[2])) / M_PI * s->input_mirror_modifier[1];
1699 1733
1700 float uf = (theta * cosf(phi) * scale + 0.5f) * ew;1734 float uf = (theta * cosf(phi) * scale + 0.5f) * ew;
1701 float vf = (theta * sinf(phi) * scale + 0.5f) * eh;1735 float vf = (theta * sinf(phi) * scale + 0.5f) * eh;
@@ -1818,8 +1852,8 @@ static void xyz_to_barrel(const V360Context *s, · 116 unmodified lines
1818{1852{
1819 const float scale = 0.99f;1853 const float scale = 0.99f;
1820 1854
1821 const float phi = atan2f(vec[0], -vec[2]);1855 const float phi = atan2f(vec[0], -vec[2]) * s->input_mirror_modifier[0];
1822 const float theta = asinf(-vec[1]);1856 const float theta = asinf(-vec[1]) * s->input_mirror_modifier[1];
1823 const float theta_range = M_PI / 4.f;1857 const float theta_range = M_PI / 4.f;
1824 1858
1825 int ew, eh;1859 int ew, eh;
@@ -1832,7 +1866,7 @@ static void xyz_to_barrel(const V360Context *s, · 6 unmodified lines
1832 ew = 4 * width / 5;1866 ew = 4 * width / 5;
1833 eh = height;1867 eh = height;
1834 1868
1835 u_shift = 0;1869 u_shift = s->ih_flip ? width / 5 : 0;
1836 v_shift = 0;1870 v_shift = 0;
1837 1871
1838 uf = (phi / M_PI * scale + 1.f) * ew / 2.f;1872 uf = (phi / M_PI * scale + 1.f) * ew / 2.f;
@@ -1841,7 +1875,7 @@ static void xyz_to_barrel(const V360Context *s, · 2 unmodified lines
1841 ew = width / 5;1875 ew = width / 5;
1842 eh = height / 2;1876 eh = height / 2;
1843 1877
1844 u_shift = 4 * ew;1878 u_shift = s->ih_flip ? 0 : 4 * ew;
1845 1879
1846 if (theta < 0.f) { // UP1880 if (theta < 0.f) { // UP
1847 uf = vec[0] / vec[1];1881 uf = vec[0] / vec[1];
@@ -1853,6 +1887,9 @@ static void xyz_to_barrel(const V360Context *s, · 5 unmodified lines
1853 v_shift = eh;1887 v_shift = eh;
1854 }1888 }
1855 1889
1890 uf *= s->input_mirror_modifier[0] * s->input_mirror_modifier[1];
1891 vf *= s->input_mirror_modifier[1];
1892
1856 uf = 0.5f * ew * (uf * scale + 1.f);1893 uf = 0.5f * ew * (uf * scale + 1.f);
1857 vf = 0.5f * eh * (vf * scale + 1.f);1894 vf = 0.5f * eh * (vf * scale + 1.f);
1858 }1895 }
@@ -1869,7 +1906,6 @@ static void xyz_to_barrel(const V360Context *s, · 10 unmodified lines
1869 vs[i + 1][j + 1] = v_shift + av_clip(vi + i, 0, eh - 1);1906 vs[i + 1][j + 1] = v_shift + av_clip(vi + i, 0, eh - 1);
1870 }1907 }
1871 }1908 }
1872
1873}1909}
1874 1910
1875static void multiply_matrix(float c[3][3], const float a[3][3], const float b[3][3])1911static void multiply_matrix(float c[3][3], const float a[3][3], const float b[3][3])
@@ -1984,7 +2020,7 @@ static int config_output(AVFilterLink *outlink) · 108 unmodified lines
1984 int err;2020 int err;
1985 int p, h, w;2021 int p, h, w;
1986 float hf, wf;2022 float hf, wf;
1987 float mirror_modifier[3];2023 float output_mirror_modifier[3];
1988 void (*in_transform)(const V360Context *s,2024 void (*in_transform)(const V360Context *s,
1989 const float *vec, int width, int height,2025 const float *vec, int width, int height,
1990 uint16_t us[4][4], uint16_t vs[4][4], float *du, float *dv);2026 uint16_t us[4][4], uint16_t vs[4][4], float *du, float *dv);
@@ -1995,6 +2031,9 @@ static int config_output(AVFilterLink *outlink) · 4 unmodified lines
1995 uint16_t *u, uint16_t *v, int16_t *ker);2031 uint16_t *u, uint16_t *v, int16_t *ker);
1996 float rot_mat[3][3];2032 float rot_mat[3][3];
1997 2033
2034 s->input_mirror_modifier[0] = s->ih_flip ? -1.f : 1.f;
2035 s->input_mirror_modifier[1] = s->iv_flip ? -1.f : 1.f;
2036
1998 switch (s->interp) {2037 switch (s->interp) {
1999 case NEAREST:2038 case NEAREST:
2000 calculate_kernel = nearest_kernel;2039 calculate_kernel = nearest_kernel;
@@ -2212,7 +2251,7 @@ static int config_output(AVFilterLink *outlink) · 211 unmodified lines
2212 }2251 }
2213 2252
2214 calculate_rotation_matrix(s->yaw, s->pitch, s->roll, rot_mat, s->rotation_order);2253 calculate_rotation_matrix(s->yaw, s->pitch, s->roll, rot_mat, s->rotation_order);
2215 set_mirror_modifier(s->h_flip, s->v_flip, s->d_flip, mirror_modifier);2254 set_mirror_modifier(s->h_flip, s->v_flip, s->d_flip, output_mirror_modifier);
2216 2255
2217 // Calculate remap data2256 // Calculate remap data
2218 for (p = 0; p < s->nb_allocated; p++) {2257 for (p = 0; p < s->nb_allocated; p++) {
@@ -2236,7 +2275,7 @@ static int config_output(AVFilterLink *outlink) · 17 unmodified lines
2236 else2275 else
2237 out_transform(s, i, j, width, height, vec);2276 out_transform(s, i, j, width, height, vec);
2238 rotate(rot_mat, vec);2277 rotate(rot_mat, vec);
2239 mirror(mirror_modifier, vec);2278 mirror(output_mirror_modifier, vec);
2240 if (s->in_transpose)2279 if (s->in_transpose)
2241 in_transform(s, vec, in_height, in_width, r_tmp.v, r_tmp.u, &du, &dv);2280 in_transform(s, vec, in_height, in_width, r_tmp.v, r_tmp.u, &du, &dv);
2242 else2281 else

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