2 * Copyright (c) 2016 Vittorio Giovara <vittorio.giovara@gmail.com>
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * @ingroup lavu_video_spherical
27 #ifndef AVUTIL_SPHERICAL_H
28 #define AVUTIL_SPHERICAL_H
34 * @defgroup lavu_video_spherical Spherical video mapping
37 * A spherical video file contains surfaces that need to be mapped onto a
38 * sphere. Depending on how the frame was converted, a different distortion
39 * transformation or surface recomposition function needs to be applied before
40 * the video should be mapped and displayed.
45 * Projection of the video surface(s) on a sphere.
47 enum AVSphericalProjection
{
49 * Video represents a sphere mapped on a flat surface using
50 * equirectangular projection.
52 AV_SPHERICAL_EQUIRECTANGULAR
,
55 * Video frame is split into 6 faces of a cube, and arranged on a
56 * 3x2 layout. Faces are oriented upwards for the front, left, right,
57 * and back faces. The up face is oriented so the top of the face is
58 * forwards and the down face is oriented so the top of the face is
64 * Video represents a portion of a sphere mapped on a flat surface
65 * using equirectangular projection. The @ref bounding fields indicate
66 * the position of the current video in a larger surface.
68 AV_SPHERICAL_EQUIRECTANGULAR_TILE
,
71 * Video frame displays as a 180 degree equirectangular projection.
73 AV_SPHERICAL_HALF_EQUIRECTANGULAR
,
76 * Video frame displays on a flat, rectangular 2D surface.
78 AV_SPHERICAL_RECTILINEAR
,
81 * Fisheye projection (Apple).
82 * See: https://developer.apple.com/documentation/coremedia/cmprojectiontype/fisheye
87 * Parametric Immersive projection (Apple).
88 * See: https://developer.apple.com/documentation/coremedia/cmprojectiontype/parametricimmersive
90 AV_SPHERICAL_PARAMETRIC_IMMERSIVE
,
94 * This structure describes how to handle spherical videos, outlining
95 * information about projection, initial layout, and any other view modifier.
97 * @note The struct must be allocated with av_spherical_alloc() and
98 * its size is not a part of the public ABI.
100 typedef struct AVSphericalMapping
{
104 enum AVSphericalProjection projection
;
107 * @name Initial orientation
109 * There fields describe additional rotations applied to the sphere after
110 * the video frame is mapped onto it. The sphere is rotated around the
111 * viewer, who remains stationary. The order of transformation is always
112 * yaw, followed by pitch, and finally by roll.
114 * The coordinate system matches the one defined in OpenGL, where the
115 * forward vector (z) is coming out of screen, and it is equivalent to
116 * a rotation matrix of R = r_y(yaw) * r_x(pitch) * r_z(roll).
118 * A positive yaw rotates the portion of the sphere in front of the viewer
119 * toward their right. A positive pitch rotates the portion of the sphere
120 * in front of the viewer upwards. A positive roll tilts the portion of
121 * the sphere in front of the viewer to the viewer's right.
123 * These values are exported as 16.16 fixed point.
125 * See this equirectangular projection as example:
130 * 90 +-------------+-------------+ 180
134 * t 0 +-------------X-------------+ 0 Roll | /
136 * h | | | 0|/_____right
138 * -90 +-------------+-------------+ -180
140 * X - the default camera center
141 * ^ - the default up vector
144 int32_t yaw
; ///< Rotation around the up vector [-180, 180].
145 int32_t pitch
; ///< Rotation around the right vector [-90, 90].
146 int32_t roll
; ///< Rotation around the forward vector [-180, 180].
152 * @name Bounding rectangle
155 * These fields indicate the location of the current tile, and where
156 * it should be mapped relative to the original surface. They are
157 * exported as 0.32 fixed point, and can be converted to classic
158 * pixel values with av_spherical_bounds().
161 * +----------------+----------+
164 * | bound_left |tile | |
165 * +<---------->| |<--->+bound_right
169 * +----------------+----------+
172 * If needed, the original video surface dimensions can be derived
173 * by adding the current stream or frame size to the related bounds,
174 * like in the following example:
177 * original_width = tile->width + bound_left + bound_right;
178 * original_height = tile->height + bound_top + bound_bottom;
181 * @note These values are valid only for the tiled equirectangular
182 * projection type (@ref AV_SPHERICAL_EQUIRECTANGULAR_TILE),
183 * and should be ignored in all other cases.
185 uint32_t bound_left
; ///< Distance from the left edge
186 uint32_t bound_top
; ///< Distance from the top edge
187 uint32_t bound_right
; ///< Distance from the right edge
188 uint32_t bound_bottom
; ///< Distance from the bottom edge
194 * Number of pixels to pad from the edge of each cube face.
196 * @note This value is valid for only for the cubemap projection type
197 * (@ref AV_SPHERICAL_CUBEMAP), and should be ignored in all other
201 } AVSphericalMapping
;
204 * Allocate a AVSphericalVideo structure and initialize its fields to default
207 * @return the newly allocated struct or NULL on failure
209 AVSphericalMapping
*av_spherical_alloc(size_t *size
);
212 * Convert the @ref bounding fields from an AVSphericalVideo
213 * from 0.32 fixed point to pixels.
215 * @param map The AVSphericalVideo map to read bound values from.
216 * @param width Width of the current frame or stream.
217 * @param height Height of the current frame or stream.
218 * @param left Pixels from the left edge.
219 * @param top Pixels from the top edge.
220 * @param right Pixels from the right edge.
221 * @param bottom Pixels from the bottom edge.
223 void av_spherical_tile_bounds(const AVSphericalMapping
*map
,
224 size_t width
, size_t height
,
225 size_t *left
, size_t *top
,
226 size_t *right
, size_t *bottom
);
229 * Provide a human-readable name of a given AVSphericalProjection.
231 * @param projection The input AVSphericalProjection.
233 * @return The name of the AVSphericalProjection, or "unknown".
235 const char *av_spherical_projection_name(enum AVSphericalProjection projection
);
238 * Get the AVSphericalProjection form a human-readable name.
240 * @param name The input string.
242 * @return The AVSphericalProjection value, or -1 if not found.
244 int av_spherical_from_name(const char *name
);
249 #endif /* AVUTIL_SPHERICAL_H */