Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
251284e4
Commit
251284e4
authored
Sep 17, 2019
by
Paul B Mahol
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avfilter/vf_v360: add mercator projection
parent
65589ad5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
0 deletions
+82
-0
filters.texi
doc/filters.texi
+3
-0
v360.h
libavfilter/v360.h
+1
-0
vf_v360.c
libavfilter/vf_v360.c
+78
-0
No files found.
doc/filters.texi
View file @
251284e4
...
@@ -18057,6 +18057,9 @@ Set horizontal/vertical/diagonal field of view. Values in degrees.
...
@@ -18057,6 +18057,9 @@ Set horizontal/vertical/diagonal field of view. Values in degrees.
If diagonal field of view is set it overrides horizontal and vertical field of view.
If diagonal field of view is set it overrides horizontal and vertical field of view.
@end table
@end table
@item mercator
Mercator format.
@end table
@end table
@item interp
@item interp
...
...
libavfilter/v360.h
View file @
251284e4
...
@@ -39,6 +39,7 @@ enum Projections {
...
@@ -39,6 +39,7 @@ enum Projections {
BARREL
,
BARREL
,
CUBEMAP_1_6
,
CUBEMAP_1_6
,
STEREOGRAPHIC
,
STEREOGRAPHIC
,
MERCATOR
,
NB_PROJECTIONS
,
NB_PROJECTIONS
,
};
};
...
...
libavfilter/vf_v360.c
View file @
251284e4
...
@@ -65,6 +65,7 @@ static const AVOption v360_options[] = {
...
@@ -65,6 +65,7 @@ static const AVOption v360_options[] = {
{
"fb"
,
"barrel facebook's 360 format"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
BARREL
},
0
,
0
,
FLAGS
,
"in"
},
{
"fb"
,
"barrel facebook's 360 format"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
BARREL
},
0
,
0
,
FLAGS
,
"in"
},
{
"c1x6"
,
"cubemap 1x6"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
CUBEMAP_1_6
},
0
,
0
,
FLAGS
,
"in"
},
{
"c1x6"
,
"cubemap 1x6"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
CUBEMAP_1_6
},
0
,
0
,
FLAGS
,
"in"
},
{
"sg"
,
"stereographic"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
STEREOGRAPHIC
},
0
,
0
,
FLAGS
,
"in"
},
{
"sg"
,
"stereographic"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
STEREOGRAPHIC
},
0
,
0
,
FLAGS
,
"in"
},
{
"mercator"
,
"mercator"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
MERCATOR
},
0
,
0
,
FLAGS
,
"in"
},
{
"output"
,
"set output projection"
,
OFFSET
(
out
),
AV_OPT_TYPE_INT
,
{.
i64
=
CUBEMAP_3_2
},
0
,
NB_PROJECTIONS
-
1
,
FLAGS
,
"out"
},
{
"output"
,
"set output projection"
,
OFFSET
(
out
),
AV_OPT_TYPE_INT
,
{.
i64
=
CUBEMAP_3_2
},
0
,
NB_PROJECTIONS
-
1
,
FLAGS
,
"out"
},
{
"e"
,
"equirectangular"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
EQUIRECTANGULAR
},
0
,
0
,
FLAGS
,
"out"
},
{
"e"
,
"equirectangular"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
EQUIRECTANGULAR
},
0
,
0
,
FLAGS
,
"out"
},
{
"equirect"
,
"equirectangular"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
EQUIRECTANGULAR
},
0
,
0
,
FLAGS
,
"out"
},
{
"equirect"
,
"equirectangular"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
EQUIRECTANGULAR
},
0
,
0
,
FLAGS
,
"out"
},
...
@@ -79,6 +80,7 @@ static const AVOption v360_options[] = {
...
@@ -79,6 +80,7 @@ static const AVOption v360_options[] = {
{
"fb"
,
"barrel facebook's 360 format"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
BARREL
},
0
,
0
,
FLAGS
,
"out"
},
{
"fb"
,
"barrel facebook's 360 format"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
BARREL
},
0
,
0
,
FLAGS
,
"out"
},
{
"c1x6"
,
"cubemap 1x6"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
CUBEMAP_1_6
},
0
,
0
,
FLAGS
,
"out"
},
{
"c1x6"
,
"cubemap 1x6"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
CUBEMAP_1_6
},
0
,
0
,
FLAGS
,
"out"
},
{
"sg"
,
"stereographic"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
STEREOGRAPHIC
},
0
,
0
,
FLAGS
,
"out"
},
{
"sg"
,
"stereographic"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
STEREOGRAPHIC
},
0
,
0
,
FLAGS
,
"out"
},
{
"mercator"
,
"mercator"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
MERCATOR
},
0
,
0
,
FLAGS
,
"out"
},
{
"interp"
,
"set interpolation method"
,
OFFSET
(
interp
),
AV_OPT_TYPE_INT
,
{.
i64
=
BILINEAR
},
0
,
NB_INTERP_METHODS
-
1
,
FLAGS
,
"interp"
},
{
"interp"
,
"set interpolation method"
,
OFFSET
(
interp
),
AV_OPT_TYPE_INT
,
{.
i64
=
BILINEAR
},
0
,
NB_INTERP_METHODS
-
1
,
FLAGS
,
"interp"
},
{
"near"
,
"nearest neighbour"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
NEAREST
},
0
,
0
,
FLAGS
,
"interp"
},
{
"near"
,
"nearest neighbour"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
NEAREST
},
0
,
0
,
FLAGS
,
"interp"
},
{
"nearest"
,
"nearest neighbour"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
NEAREST
},
0
,
0
,
FLAGS
,
"interp"
},
{
"nearest"
,
"nearest neighbour"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
NEAREST
},
0
,
0
,
FLAGS
,
"interp"
},
...
@@ -1516,6 +1518,70 @@ static void xyz_to_equirect(const V360Context *s,
...
@@ -1516,6 +1518,70 @@ static void xyz_to_equirect(const V360Context *s,
}
}
}
}
/**
* Calculate frame position in mercator format for corresponding 3D coordinates on sphere.
*
* @param s filter context
* @param vec coordinates on sphere
* @param width frame width
* @param height frame height
* @param us horizontal coordinates for interpolation window
* @param vs vertical coordinates for interpolation window
* @param du horizontal relative coordinate
* @param dv vertical relative coordinate
*/
static
void
xyz_to_mercator
(
const
V360Context
*
s
,
const
float
*
vec
,
int
width
,
int
height
,
uint16_t
us
[
4
][
4
],
uint16_t
vs
[
4
][
4
],
float
*
du
,
float
*
dv
)
{
const
float
phi
=
atan2f
(
vec
[
0
],
-
vec
[
2
])
*
s
->
input_mirror_modifier
[
0
];
const
float
theta
=
0
.
5
f
*
asinhf
(
vec
[
1
]
/
sqrtf
(
1
.
f
-
vec
[
1
]
*
vec
[
1
]))
*
s
->
input_mirror_modifier
[
1
];
float
uf
,
vf
;
int
ui
,
vi
;
uf
=
(
phi
/
M_PI
+
1
.
f
)
*
width
/
2
.
f
;
vf
=
(
theta
/
M_PI
+
1
.
f
)
*
height
/
2
.
f
;
ui
=
floorf
(
uf
);
vi
=
floorf
(
vf
);
*
du
=
uf
-
ui
;
*
dv
=
vf
-
vi
;
for
(
int
i
=
-
1
;
i
<
3
;
i
++
)
{
for
(
int
j
=
-
1
;
j
<
3
;
j
++
)
{
us
[
i
+
1
][
j
+
1
]
=
mod
(
ui
+
j
,
width
);
vs
[
i
+
1
][
j
+
1
]
=
av_clip
(
vi
+
i
,
0
,
height
-
1
);
}
}
}
/**
* Calculate 3D coordinates on sphere for corresponding frame position in mercator format.
*
* @param s filter context
* @param i horizontal position on frame [0, width)
* @param j vertical position on frame [0, height)
* @param width frame width
* @param height frame height
* @param vec coordinates on sphere
*/
static
void
mercator_to_xyz
(
const
V360Context
*
s
,
int
i
,
int
j
,
int
width
,
int
height
,
float
*
vec
)
{
const
float
phi
=
((
2
.
f
*
i
)
/
width
-
1
.
f
)
*
M_PI
;
const
float
theta
=
atanf
(
sinhf
(((
2
.
f
*
j
)
/
height
-
1
.
f
)
*
2
.
f
*
M_PI
));
const
float
sin_phi
=
sinf
(
phi
);
const
float
cos_phi
=
cosf
(
phi
);
const
float
sin_theta
=
sinf
(
theta
);
const
float
cos_theta
=
cosf
(
theta
);
vec
[
0
]
=
cos_theta
*
sin_phi
;
vec
[
1
]
=
-
sin_theta
;
vec
[
2
]
=
-
cos_theta
*
cos_phi
;
}
/**
/**
* Prepare data for processing equi-angular cubemap input format.
* Prepare data for processing equi-angular cubemap input format.
*
*
...
@@ -2357,6 +2423,12 @@ static int config_output(AVFilterLink *outlink)
...
@@ -2357,6 +2423,12 @@ static int config_output(AVFilterLink *outlink)
wf
=
w
;
wf
=
w
;
hf
=
h
/
2
.
f
;
hf
=
h
/
2
.
f
;
break
;
break
;
case
MERCATOR
:
s
->
in_transform
=
xyz_to_mercator
;
err
=
0
;
wf
=
w
;
hf
=
h
;
break
;
default
:
default
:
av_log
(
ctx
,
AV_LOG_ERROR
,
"Specified input format is not handled.
\n
"
);
av_log
(
ctx
,
AV_LOG_ERROR
,
"Specified input format is not handled.
\n
"
);
return
AVERROR_BUG
;
return
AVERROR_BUG
;
...
@@ -2421,6 +2493,12 @@ static int config_output(AVFilterLink *outlink)
...
@@ -2421,6 +2493,12 @@ static int config_output(AVFilterLink *outlink)
w
=
roundf
(
wf
);
w
=
roundf
(
wf
);
h
=
roundf
(
hf
*
2
.
f
);
h
=
roundf
(
hf
*
2
.
f
);
break
;
break
;
case
MERCATOR
:
s
->
out_transform
=
mercator_to_xyz
;
prepare_out
=
NULL
;
w
=
roundf
(
wf
);
h
=
roundf
(
hf
);
break
;
default
:
default
:
av_log
(
ctx
,
AV_LOG_ERROR
,
"Specified output format is not handled.
\n
"
);
av_log
(
ctx
,
AV_LOG_ERROR
,
"Specified output format is not handled.
\n
"
);
return
AVERROR_BUG
;
return
AVERROR_BUG
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment