[FFmpeg-cvslog] spherical: Add tiled equirectangular type and projection-specific properties

Vittorio Giovara git at videolan.org
Tue Oct 17 22:51:02 EEST 2017


ffmpeg | branch: master | Vittorio Giovara <vittorio.giovara at gmail.com> | Fri Feb 10 15:26:55 2017 -0500| [6bce6aa17d7f22bf46fde0d4610a41d2af0c0e48] | committer: Vittorio Giovara

spherical: Add tiled equirectangular type and projection-specific properties

Signed-off-by: Vittorio Giovara <vittorio.giovara at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6bce6aa17d7f22bf46fde0d4610a41d2af0c0e48
---

 avtools/avprobe.c     | 18 ++++++++++---
 doc/APIchanges        |  5 ++++
 libavformat/dump.c    | 15 +++++++++--
 libavutil/spherical.c | 18 +++++++++++++
 libavutil/spherical.h | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++
 libavutil/version.h   |  2 +-
 6 files changed, 126 insertions(+), 6 deletions(-)

diff --git a/avtools/avprobe.c b/avtools/avprobe.c
index 613e090be6..68f19220c8 100644
--- a/avtools/avprobe.c
+++ b/avtools/avprobe.c
@@ -792,11 +792,23 @@ static void show_stream(InputFile *ifile, InputStream *ist)
                 spherical = (AVSphericalMapping *)sd->data;
                 probe_object_header("spherical");
 
-                if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR)
+                if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR) {
                     probe_str("projection", "equirectangular");
-                else if (spherical->projection == AV_SPHERICAL_CUBEMAP)
+                } else if (spherical->projection == AV_SPHERICAL_CUBEMAP) {
                     probe_str("projection", "cubemap");
-                else
+                    probe_int("padding", spherical->padding);
+                } else if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) {
+                    size_t l, t, r, b;
+                    av_spherical_tile_bounds(spherical, par->width, par->height,
+                                             &l, &t, &r, &b);
+                    probe_str("projection", "tiled equirectangular");
+                    probe_object_header("bounding");
+                    probe_int("left", l);
+                    probe_int("top", t);
+                    probe_int("right", r);
+                    probe_int("bottom", b);
+                    probe_object_footer("bounding");
+                } else
                     probe_str("projection", "unknown");
 
                 probe_object_header("orientation");
diff --git a/doc/APIchanges b/doc/APIchanges
index a919ffb2bf..9367a5fc41 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,11 @@ libavutil:     2015-08-28
 
 API changes, most recent first:
 
+2017-02-10 - xxxxxxx - lavu 55.33.0 - spherical.h
+  Add AV_SPHERICAL_EQUIRECTANGULAR_TILE, av_spherical_tile_bounds(),
+  and projection-specific properties (bound_left, bound_top, bound_right,
+  bound_bottom, padding) to AVSphericalMapping.
+
 2017-xx-xx - xxxxxxx - lavc 57.34.0 - avcodec.h
   Add AVCodecContext.hw_device_ctx.
 
diff --git a/libavformat/dump.c b/libavformat/dump.c
index 660df0a533..7514aee7ac 100644
--- a/libavformat/dump.c
+++ b/libavformat/dump.c
@@ -307,7 +307,7 @@ static void dump_cpb(void *ctx, AVPacketSideData *sd)
            cpb->vbv_delay);
 }
 
-static void dump_spherical(void *ctx, AVPacketSideData *sd)
+static void dump_spherical(void *ctx, AVCodecParameters *par, AVPacketSideData *sd)
 {
     AVSphericalMapping *spherical = (AVSphericalMapping *)sd->data;
     double yaw, pitch, roll;
@@ -321,6 +321,8 @@ static void dump_spherical(void *ctx, AVPacketSideData *sd)
         av_log(ctx, AV_LOG_INFO, "equirectangular ");
     else if (spherical->projection == AV_SPHERICAL_CUBEMAP)
         av_log(ctx, AV_LOG_INFO, "cubemap ");
+    else if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE)
+        av_log(ctx, AV_LOG_INFO, "tiled equirectangular ");
     else {
         av_log(ctx, AV_LOG_WARNING, "unknown");
         return;
@@ -330,6 +332,15 @@ static void dump_spherical(void *ctx, AVPacketSideData *sd)
     pitch = ((double)spherical->pitch) / (1 << 16);
     roll = ((double)spherical->roll) / (1 << 16);
     av_log(ctx, AV_LOG_INFO, "(%f/%f/%f) ", yaw, pitch, roll);
+
+    if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) {
+        size_t l, t, r, b;
+        av_spherical_tile_bounds(spherical, par->width, par->height,
+                                 &l, &t, &r, &b);
+        av_log(ctx, AV_LOG_INFO, "[%zu, %zu, %zu, %zu] ", l, t, r, b);
+    } else if (spherical->projection == AV_SPHERICAL_CUBEMAP) {
+        av_log(ctx, AV_LOG_INFO, "[pad %zu] ", spherical->padding);
+    }
 }
 
 static void dump_sidedata(void *ctx, AVStream *st, const char *indent)
@@ -382,7 +393,7 @@ static void dump_sidedata(void *ctx, AVStream *st, const char *indent)
             break;
         case AV_PKT_DATA_SPHERICAL:
             av_log(ctx, AV_LOG_INFO, "spherical: ");
-            dump_spherical(ctx, &sd);
+            dump_spherical(ctx, st->codecpar, &sd);
             break;
         default:
             av_log(ctx, AV_LOG_WARNING,
diff --git a/libavutil/spherical.c b/libavutil/spherical.c
index f6e53d1bd2..f5accc487d 100644
--- a/libavutil/spherical.c
+++ b/libavutil/spherical.c
@@ -32,3 +32,21 @@ AVSphericalMapping *av_spherical_alloc(size_t *size)
 
     return spherical;
 }
+
+void av_spherical_tile_bounds(AVSphericalMapping *map,
+                              size_t width, size_t height,
+                              size_t *left, size_t *top,
+                              size_t *right, size_t *bottom)
+{
+    /* conversion from 0.32 coordinates to pixels */
+    uint64_t orig_width  = (uint64_t) width  * UINT32_MAX /
+                           (UINT32_MAX - map->bound_right  - map->bound_left);
+    uint64_t orig_height = (uint64_t) height * UINT32_MAX /
+                           (UINT32_MAX - map->bound_bottom - map->bound_top);
+
+    /* add a (UINT32_MAX - 1) to round up integer division */
+    *left   = (orig_width  * map->bound_left + UINT32_MAX - 1) / UINT32_MAX;
+    *top    = (orig_height * map->bound_top  + UINT32_MAX - 1) / UINT32_MAX;
+    *right  = orig_width  - width  - *left;
+    *bottom = orig_height - height - *top;
+}
diff --git a/libavutil/spherical.h b/libavutil/spherical.h
index 0045eb974a..e7fc1d69fb 100644
--- a/libavutil/spherical.h
+++ b/libavutil/spherical.h
@@ -63,6 +63,13 @@ enum AVSphericalProjection {
      * to the back.
      */
     AV_SPHERICAL_CUBEMAP,
+
+    /**
+     * Video represents a portion of a sphere mapped on a flat surface
+     * using equirectangular projection. The @ref bounding fields indicate
+     * the position of the current video in a larger surface.
+     */
+    AV_SPHERICAL_EQUIRECTANGULAR_TILE,
 };
 
 /**
@@ -122,6 +129,57 @@ typedef struct AVSphericalMapping {
     /**
      * @}
      */
+
+    /**
+     * @name Bounding rectangle
+     * @anchor bounding
+     * @{
+     * These fields indicate the location of the current tile, and where
+     * it should be mapped relative to the original surface. They are
+     * exported as 0.32 fixed point, and can be converted to classic
+     * pixel values with av_spherical_bounds().
+     *
+     * @code{.unparsed}
+     *      +----------------+----------+
+     *      |                |bound_top |
+     *      |            +--------+     |
+     *      | bound_left |tile    |     |
+     *      +<---------->|        |<--->+bound_right
+     *      |            +--------+     |
+     *      |                |          |
+     *      |    bound_bottom|          |
+     *      +----------------+----------+
+     * @endcode
+     *
+     * If needed, the original video surface dimensions can be derived
+     * by adding the current stream or frame size to the related bounds,
+     * like in the following example:
+     *
+     * @code{c}
+     *     original_width  = tile->width  + bound_left + bound_right;
+     *     original_height = tile->height + bound_top  + bound_bottom;
+     * @endcode
+     *
+     * @note These values are valid only for the tiled equirectangular
+     *       projection type (@ref AV_SPHERICAL_EQUIRECTANGULAR_TILE),
+     *       and should be ignored in all other cases.
+     */
+    size_t bound_left;   ///< Distance from the left edge
+    size_t bound_top;    ///< Distance from the top edge
+    size_t bound_right;  ///< Distance from the right edge
+    size_t bound_bottom; ///< Distance from the bottom edge
+    /**
+     * @}
+     */
+
+    /**
+     * Number of pixels to pad from the edge of each cube face.
+     *
+     * @note This value is valid for only for the cubemap projection type
+     *       (@ref AV_SPHERICAL_CUBEMAP), and should be ignored in all other
+     *       cases.
+     */
+    size_t padding;
 } AVSphericalMapping;
 
 /**
@@ -133,6 +191,22 @@ typedef struct AVSphericalMapping {
 AVSphericalMapping *av_spherical_alloc(size_t *size);
 
 /**
+ * Convert the @ref bounding fields from an AVSphericalVideo
+ * from 0.32 fixed point to pixels.
+ *
+ * @param map    The AVSphericalVideo map to read bound values from.
+ * @param width  Width of the current frame or stream.
+ * @param height Height of the current frame or stream.
+ * @param left   Pixels from the left edge.
+ * @param top    Pixels from the top edge.
+ * @param right  Pixels from the right edge.
+ * @param bottom Pixels from the bottom edge.
+ */
+void av_spherical_tile_bounds(AVSphericalMapping *map,
+                              size_t width, size_t height,
+                              size_t *left, size_t *top,
+                              size_t *right, size_t *bottom);
+/**
  * @}
  * @}
  */
diff --git a/libavutil/version.h b/libavutil/version.h
index 5dbc57cc1b..0f2b684fa8 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -54,7 +54,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR 55
-#define LIBAVUTIL_VERSION_MINOR 32
+#define LIBAVUTIL_VERSION_MINOR 33
 #define LIBAVUTIL_VERSION_MICRO  0
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \



More information about the ffmpeg-cvslog mailing list