History

avfilter/vf_v360: add option to pick rotation order

Paul B Mahol committed 7 years ago

Commit cb8c3531 parent d1315413 files · +100 −15Browse files

Unified · Split

3 files
  1. doc/filters.texi +14 −0
  2. libavfilter/v360.h +13 −4
  3. libavfilter/vf_v360.c +73 −11
doc/filters.texi+14−0
@@ -18065,6 +18065,20 @@ Default resolution depends on formats. · 18064 unmodified lines
18065@item roll18065@item roll
18066Set rotation for the output video. Values in degrees.18066Set rotation for the output video. Values in degrees.
18067 18067
18068@item rorder
18069Set rotation order for the output video. Choose one item for each position.
18070
18071@table @samp
18072@item y, Y
18073yaw
18074@item p, P
18075pitch
18076@item r, R
18077roll
18078@end table
18079
18080Default value is @b{@samp{ypr}}.
18081
18068@item h_flip18082@item h_flip
18069@item v_flip18083@item v_flip
18070@item d_flip18084@item d_flip
libavfilter/v360.h+13−4
@@ -70,20 +70,29 @@ enum Rotation { · 69 unmodified lines
70 NB_ROTATIONS,70 NB_ROTATIONS,
71};71};
72 72
73enum RotationOrder {
74 YAW,
75 PITCH,
76 ROLL,
77 NB_RORDERS,
78};
79
73typedef struct V360Context {80typedef struct V360Context {
74 const AVClass *class;81 const AVClass *class;
75 int in, out;82 int in, out;
76 int interp;83 int interp;
77 int width, height;84 int width, height;
78 char* in_forder;85 char *in_forder;
79 char* out_forder;86 char *out_forder;
80 char* in_frot;87 char *in_frot;
81 char* out_frot;88 char *out_frot;
89 char *rorder;
82 90
83 int in_cubemap_face_order[6];91 int in_cubemap_face_order[6];
84 int out_cubemap_direction_order[6];92 int out_cubemap_direction_order[6];
85 int in_cubemap_face_rotation[6];93 int in_cubemap_face_rotation[6];
86 int out_cubemap_face_rotation[6];94 int out_cubemap_face_rotation[6];
95 int rotation_order[3];
87 96
88 float in_pad, out_pad;97 float in_pad, out_pad;
89 98
libavfilter/vf_v360.c+73−11
@@ -90,6 +90,7 @@ static const AVOption v360_options[] = { · 89 unmodified lines
90 { "yaw", "yaw rotation", OFFSET(yaw), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180.f, 180.f, FLAGS, "yaw"},90 { "yaw", "yaw rotation", OFFSET(yaw), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180.f, 180.f, FLAGS, "yaw"},
91 { "pitch", "pitch rotation", OFFSET(pitch), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180.f, 180.f, FLAGS, "pitch"},91 { "pitch", "pitch rotation", OFFSET(pitch), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180.f, 180.f, FLAGS, "pitch"},
92 { "roll", "roll rotation", OFFSET(roll), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180.f, 180.f, FLAGS, "roll"},92 { "roll", "roll rotation", OFFSET(roll), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180.f, 180.f, FLAGS, "roll"},
93 { "rorder", "rotation order", OFFSET(rorder), AV_OPT_TYPE_STRING, {.str="ypr"}, 0, 0, FLAGS, "rorder"},
93 { "h_fov", "horizontal field of view", OFFSET(h_fov), AV_OPT_TYPE_FLOAT, {.dbl=90.f}, 0.f, 180.f, FLAGS, "h_fov"},94 { "h_fov", "horizontal field of view", OFFSET(h_fov), AV_OPT_TYPE_FLOAT, {.dbl=90.f}, 0.f, 180.f, FLAGS, "h_fov"},
94 { "v_fov", "vertical field of view", OFFSET(v_fov), AV_OPT_TYPE_FLOAT, {.dbl=45.f}, 0.f, 90.f, FLAGS, "v_fov"},95 { "v_fov", "vertical field of view", OFFSET(v_fov), AV_OPT_TYPE_FLOAT, {.dbl=45.f}, 0.f, 90.f, FLAGS, "v_fov"},
95 { "h_flip", "flip video horizontally", OFFSET(h_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "h_flip"},96 { "h_flip", "flip video horizontally", OFFSET(h_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "h_flip"},
@@ -499,6 +500,26 @@ static int get_rotation(char c) · 403 unmodified lines
499 }500 }
500}501}
501 502
503/**
504 * Convert char to corresponding rotation order.
505 */
506static int get_rorder(char c)
507{
508 switch (c) {
509 case 'Y':
510 case 'y':
511 return YAW;
512 case 'P':
513 case 'p':
514 return PITCH;
515 case 'R':
516 case 'r':
517 return ROLL;
518 default:
519 return -1;
520 }
521}
522
502/**523/**
503 * Prepare data for processing cubemap input format.524 * Prepare data for processing cubemap input format.
504 *525 *
@@ -1849,11 +1870,26 @@ static void xyz_to_barrel(const V360Context *s, · 1344 unmodified lines
1849 1870
1850}1871}
1851 1872
1873static void multiply_matrix(float c[3][3], const float a[3][3], const float b[3][3])
1874{
1875 for (int i = 0; i < 3; i++) {
1876 for (int j = 0; j < 3; j++) {
1877 float sum = 0;
1878
1879 for (int k = 0; k < 3; k++)
1880 sum += a[i][k] * b[k][j];
1881
1882 c[i][j] = sum;
1883 }
1884 }
1885}
1886
1852/**1887/**
1853 * Calculate rotation matrix for yaw/pitch/roll angles.1888 * Calculate rotation matrix for yaw/pitch/roll angles.
1854 */1889 */
1855static inline void calculate_rotation_matrix(float yaw, float pitch, float roll,1890static inline void calculate_rotation_matrix(float yaw, float pitch, float roll,
1856 float rot_mat[3][3])1891 float rot_mat[3][3],
1892 const int rotation_order[3])
1857{1893{
1858 const float yaw_rad = yaw * M_PI / 180.f;1894 const float yaw_rad = yaw * M_PI / 180.f;
1859 const float pitch_rad = pitch * M_PI / 180.f;1895 const float pitch_rad = pitch * M_PI / 180.f;
@@ -1866,17 +1902,23 @@ static inline void calculate_rotation_matrix(float yaw, float pitch, float roll, · 6 unmodified lines
1866 const float sin_roll = sinf(roll_rad);1902 const float sin_roll = sinf(roll_rad);
1867 const float cos_roll = cosf(roll_rad);1903 const float cos_roll = cosf(roll_rad);
1868 1904
1869 rot_mat[0][0] = sin_yaw * sin_pitch * sin_roll + cos_yaw * cos_roll;1905 float m[3][3][3];
1870 rot_mat[0][1] = sin_yaw * sin_pitch * cos_roll - cos_yaw * sin_roll;1906 float temp[3][3];
1871 rot_mat[0][2] = sin_yaw * cos_pitch;1907
1908 m[0][0][0] = cos_yaw; m[0][0][1] = 0; m[0][0][2] = sin_yaw;
1909 m[0][1][0] = 0; m[0][1][1] = 1; m[0][1][2] = 0;
1910 m[0][2][0] = -sin_yaw; m[0][2][1] = 0; m[0][2][2] = cos_yaw;
1872 1911
1873 rot_mat[1][0] = cos_pitch * sin_roll;1912 m[1][0][0] = 1; m[1][0][1] = 0; m[1][0][2] = 0;
1874 rot_mat[1][1] = cos_pitch * cos_roll;1913 m[1][1][0] = 0; m[1][1][1] = cos_pitch; m[1][1][2] = -sin_pitch;
1875 rot_mat[1][2] = -sin_pitch;1914 m[1][2][0] = 0; m[1][2][1] = sin_pitch; m[1][2][2] = cos_pitch;
1876 1915
1877 rot_mat[2][0] = cos_yaw * sin_pitch * sin_roll - sin_yaw * cos_roll;1916 m[2][0][0] = cos_roll; m[2][0][1] = -sin_roll; m[2][0][2] = 0;
1878 rot_mat[2][1] = cos_yaw * sin_pitch * cos_roll + sin_yaw * sin_roll;1917 m[2][1][0] = sin_roll; m[2][1][1] = cos_roll; m[2][1][2] = 0;
1879 rot_mat[2][2] = cos_yaw * cos_pitch;1918 m[2][2][0] = 0; m[2][2][1] = 0; m[2][2][2] = 1;
1919
1920 multiply_matrix(temp, m[rotation_order[0]], m[rotation_order[1]]);
1921 multiply_matrix(rot_mat, temp, m[rotation_order[2]]);
1880}1922}
1881 1923
1882/**1924/**
@@ -1986,6 +2028,26 @@ static int config_output(AVFilterLink *outlink) · 103 unmodified lines
1986 2028
1987 ff_v360_init(s, depth);2029 ff_v360_init(s, depth);
1988 2030
2031 for (int order = 0; order < NB_RORDERS; order++) {
2032 const char c = s->rorder[order];
2033 int rorder;
2034
2035 if (c == '\0') {
2036 av_log(ctx, AV_LOG_ERROR,
2037 "Incomplete rorder option. Direction for all 3 rotation orders should be specified.\n");
2038 return AVERROR(EINVAL);
2039 }
2040
2041 rorder = get_rorder(c);
2042 if (rorder == -1) {
2043 av_log(ctx, AV_LOG_ERROR,
2044 "Incorrect rotation order symbol '%c' in rorder option.\n", c);
2045 return AVERROR(EINVAL);
2046 }
2047
2048 s->rotation_order[order] = rorder;
2049 }
2050
1989 switch (s->in) {2051 switch (s->in) {
1990 case EQUIRECTANGULAR:2052 case EQUIRECTANGULAR:
1991 in_transform = xyz_to_equirect;2053 in_transform = xyz_to_equirect;
@@ -2141,7 +2203,7 @@ static int config_output(AVFilterLink *outlink) · 149 unmodified lines
2141 allocate_plane(s, sizeof_uv, sizeof_ker, 2);2203 allocate_plane(s, sizeof_uv, sizeof_ker, 2);
2142 }2204 }
2143 2205
2144 calculate_rotation_matrix(s->yaw, s->pitch, s->roll, rot_mat);2206 calculate_rotation_matrix(s->yaw, s->pitch, s->roll, rot_mat, s->rotation_order);
2145 set_mirror_modifier(s->h_flip, s->v_flip, s->d_flip, mirror_modifier);2207 set_mirror_modifier(s->h_flip, s->v_flip, s->d_flip, mirror_modifier);
2146 2208
2147 // Calculate remap data2209 // Calculate remap data

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