[x264-devel] matroska: Correctly write display width and height in stereo mode

Vittorio Giovara git at videolan.org
Tue Feb 24 20:37:44 CET 2015


x264 | branch: master | Vittorio Giovara <vittorio.giovara at gmail.com> | Tue Jan 20 16:28:54 2015 +0000| [4c75f3d729aaf3bcb00edf789c71f09495374bdf] | committer: Anton Mitrofanov

matroska: Correctly write display width and height in stereo mode

According to the specifications, when stereo mode is set, these values
represent the single view size.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=4c75f3d729aaf3bcb00edf789c71f09495374bdf
---

 output/matroska.c      |   31 +++++++++++++++++++------------
 output/matroska_ebml.c |    6 ++----
 2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/output/matroska.c b/output/matroska.c
index b1c3f13..a74a274 100644
--- a/output/matroska.c
+++ b/output/matroska.c
@@ -62,9 +62,14 @@ static int open_file( char *psz_filename, hnd_t *p_handle, cli_output_opt_t *opt
     return 0;
 }
 
+#define STEREO_COUNT 6
+static const uint8_t stereo_modes[STEREO_COUNT] = {5,9,7,1,3,13};
+static const uint8_t stereo_w_div[STEREO_COUNT] = {1,2,1,2,1,1};
+static const uint8_t stereo_h_div[STEREO_COUNT] = {1,1,2,1,2,1};
+
 static int set_param( hnd_t handle, x264_param_t *p_param )
 {
-    mkv_hnd_t   *p_mkv = handle;
+    mkv_hnd_t *p_mkv = handle;
     int64_t dw, dh;
 
     if( p_param->i_fps_num > 0 && !p_param->b_vfr_input )
@@ -77,25 +82,27 @@ static int set_param( hnd_t handle, x264_param_t *p_param )
         p_mkv->frame_duration = 0;
     }
 
-    p_mkv->width = p_mkv->d_width = p_param->i_width;
-    p_mkv->height = p_mkv->d_height = p_param->i_height;
+    dw = p_mkv->width = p_param->i_width;
+    dh = p_mkv->height = p_param->i_height;
     p_mkv->display_size_units = DS_PIXELS;
-    p_mkv->stereo_mode = p_param->i_frame_packing;
-
+    p_mkv->stereo_mode = -1;
+    if( p_param->i_frame_packing >= 0 && p_param->i_frame_packing < STEREO_COUNT )
+    {
+        p_mkv->stereo_mode = stereo_modes[p_param->i_frame_packing];
+        dw /= stereo_w_div[p_param->i_frame_packing];
+        dh /= stereo_h_div[p_param->i_frame_packing];
+    }
     if( p_param->vui.i_sar_width && p_param->vui.i_sar_height
         && p_param->vui.i_sar_width != p_param->vui.i_sar_height )
     {
         if ( p_param->vui.i_sar_width > p_param->vui.i_sar_height ) {
-            dw = (int64_t)p_param->i_width * p_param->vui.i_sar_width / p_param->vui.i_sar_height;
-            dh = p_param->i_height;
+            dw = dw * p_param->vui.i_sar_width / p_param->vui.i_sar_height;
         } else {
-            dw = p_param->i_width;
-            dh = (int64_t)p_param->i_height * p_param->vui.i_sar_height / p_param->vui.i_sar_width;
+            dh = dh * p_param->vui.i_sar_height / p_param->vui.i_sar_width;
         }
-
-        p_mkv->d_width = (int)dw;
-        p_mkv->d_height = (int)dh;
     }
+    p_mkv->d_width = (int)dw;
+    p_mkv->d_height = (int)dh;
 
     p_mkv->i_timebase_num = p_param->i_timebase_num;
     p_mkv->i_timebase_den = p_param->i_timebase_den;
diff --git a/output/matroska_ebml.c b/output/matroska_ebml.c
index ac6be87..db2c35f 100644
--- a/output/matroska_ebml.c
+++ b/output/matroska_ebml.c
@@ -317,8 +317,6 @@ mk_writer *mk_create_writer( const char *filename )
     return w;
 }
 
-static const uint8_t mk_stereo_modes[6] = {5,9,7,1,3,13};
-
 int mk_write_header( mk_writer *w, const char *writing_app,
                      const char *codec_id,
                      const void *codec_private, unsigned codec_private_size,
@@ -381,8 +379,8 @@ int mk_write_header( mk_writer *w, const char *writing_app,
     CHECK( mk_write_uint( v, 0x54b2, display_size_units ) );
     CHECK( mk_write_uint( v, 0x54b0, d_width ) );
     CHECK( mk_write_uint( v, 0x54ba, d_height ) );
-    if( stereo_mode >= 0 && stereo_mode <= 5 )
-        CHECK( mk_write_uint( v, 0x53b8, mk_stereo_modes[stereo_mode] ) );
+    if( stereo_mode >= 0 )
+        CHECK( mk_write_uint( v, 0x53b8, stereo_mode ) );
     CHECK( mk_close_context( v, 0 ) );
 
     CHECK( mk_close_context( ti, 0 ) );



More information about the x264-devel mailing list