aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2017-03-08 16:12:32 -0300
committerJames Almer <jamrial@gmail.com>2017-03-09 13:57:03 -0300
commit58eb0f57f6702d57b6f97ec5010657bb2c076eff (patch)
treee753d0150d2c33d4ae3653ce13699d49c3473394
parentf940492bb241d1cf27175f40e580c51c20d6ebc3 (diff)
downloadffmpeg-58eb0f57f6702d57b6f97ec5010657bb2c076eff.tar.gz
avformat/matroskaenc: add support for Spherical Video elements
Reviewed-by: Vittorio Giovara <vittorio.giovara@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
-rw-r--r--libavformat/matroskaenc.c79
-rw-r--r--libavformat/version.h2
2 files changed, 80 insertions, 1 deletions
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 1605f0cafe..df77313675 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -918,6 +918,82 @@ static int mkv_write_video_color(AVIOContext *pb, AVCodecParameters *par, AVStre
return 0;
}
+static int mkv_write_video_projection(AVFormatContext *s, AVIOContext *pb, AVStream *st)
+{
+ int side_data_size = 0;
+ const AVSphericalMapping *spherical =
+ (const AVSphericalMapping*) av_stream_get_side_data(st, AV_PKT_DATA_SPHERICAL,
+ &side_data_size);
+
+ if (side_data_size) {
+ AVIOContext *dyn_cp;
+ uint8_t *projection_ptr;
+ int ret, projection_size;
+
+ ret = avio_open_dyn_buf(&dyn_cp);
+ if (ret < 0)
+ return ret;
+
+ switch (spherical->projection) {
+ case AV_SPHERICAL_EQUIRECTANGULAR:
+ put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONTYPE,
+ MATROSKA_VIDEO_PROJECTION_TYPE_EQUIRECTANGULAR);
+ break;
+ case AV_SPHERICAL_EQUIRECTANGULAR_TILE:
+ {
+ AVIOContext b;
+ uint8_t private[20];
+ ffio_init_context(&b, private, sizeof(private),
+ 1, NULL, NULL, NULL, NULL);
+ put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONTYPE,
+ MATROSKA_VIDEO_PROJECTION_TYPE_EQUIRECTANGULAR);
+ avio_wb32(&b, 0); // version + flags
+ avio_wb32(&b, spherical->bound_top);
+ avio_wb32(&b, spherical->bound_bottom);
+ avio_wb32(&b, spherical->bound_left);
+ avio_wb32(&b, spherical->bound_right);
+ put_ebml_binary(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONPRIVATE, private, sizeof(private));
+ break;
+ }
+ case AV_SPHERICAL_CUBEMAP:
+ {
+ AVIOContext b;
+ uint8_t private[12];
+ ffio_init_context(&b, private, sizeof(private),
+ 1, NULL, NULL, NULL, NULL);
+ put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONTYPE,
+ MATROSKA_VIDEO_PROJECTION_TYPE_CUBEMAP);
+ avio_wb32(&b, 0); // version + flags
+ avio_wb32(&b, 0); // layout
+ avio_wb32(&b, spherical->padding);
+ put_ebml_binary(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONPRIVATE, private, sizeof(private));
+ break;
+ }
+ default:
+ av_log(s, AV_LOG_WARNING, "Unknown projection type\n");
+ goto end;
+ }
+
+ if (spherical->yaw)
+ put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONPOSEYAW, (double)spherical->yaw / (1 << 16));
+ if (spherical->pitch)
+ put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONPOSEPITCH, (double)spherical->pitch / (1 << 16));
+ if (spherical->roll)
+ put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONPOSEROLL, (double)spherical->roll / (1 << 16));
+
+end:
+ projection_size = avio_close_dyn_buf(dyn_cp, &projection_ptr);
+ if (projection_size) {
+ ebml_master projection = start_ebml_master(pb, MATROSKA_ID_VIDEOPROJECTION, projection_size);
+ avio_write(pb, projection_ptr, projection_size);
+ end_ebml_master(pb, projection);
+ }
+ av_freep(&projection_ptr);
+ }
+
+ return 0;
+}
+
static void mkv_write_field_order(AVIOContext *pb, int mode,
enum AVFieldOrder field_order)
{
@@ -1268,6 +1344,9 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv,
ret = mkv_write_video_color(pb, par, st);
if (ret < 0)
return ret;
+ ret = mkv_write_video_projection(s, pb, st);
+ if (ret < 0)
+ return ret;
end_ebml_master(pb, subinfo);
break;
diff --git a/libavformat/version.h b/libavformat/version.h
index cd505242ef..dc689d45fb 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -33,7 +33,7 @@
// Also please add any ticket numbers that you believe might be affected here
#define LIBAVFORMAT_VERSION_MAJOR 57
#define LIBAVFORMAT_VERSION_MINOR 66
-#define LIBAVFORMAT_VERSION_MICRO 103
+#define LIBAVFORMAT_VERSION_MICRO 104
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \