int width, height, d_width, d_height;
+ int display_size_units;
+
int64_t frame_duration;
char b_writing_frame;
p_mkv->frame_duration = 0;
}
- p_mkv->width = p_param->i_width;
- p_mkv->height = p_param->i_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;
- dh = (int64_t)p_param->i_height * p_param->vui.i_sar_height;
- }
- else
- {
- dw = p_param->i_width;
- dh = p_param->i_height;
- }
+ p_mkv->width = p_mkv->d_width = p_param->i_width;
+ p_mkv->height = p_mkv->d_height = p_param->i_height;
+ p_mkv->display_size_units = DS_PIXELS;
- if( dw > 0 && dh > 0 )
+ 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 )
{
- int64_t x = gcd( dw, dh );
- dw /= x;
- dh /= x;
+ 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;
+ } 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;
+ }
+
+ 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;
ret = mk_writeHeader( p_mkv->w, "x264" X264_VERSION, "V_MPEG4/ISO/AVC",
avcC, avcC_len, p_mkv->frame_duration, 50000,
p_mkv->width, p_mkv->height,
- p_mkv->d_width, p_mkv->d_height );
+ p_mkv->d_width, p_mkv->d_height, p_mkv->display_size_units );
if( ret < 0 )
return ret;
int64_t default_frame_duration,
int64_t timescale,
unsigned width, unsigned height,
- unsigned d_width, unsigned d_height )
+ unsigned d_width, unsigned d_height, int display_size_units )
{
mk_context *c, *ti, *v;
return -1;
CHECK( mk_write_uint( v, 0xb0, width ) );
CHECK( mk_write_uint( v, 0xba, height ) );
+ 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 ) );
CHECK( mk_close_context( v, 0 ) );
#ifndef X264_MATROSKA_EBML_H
#define X264_MATROSKA_EBML_H
+/* Matroska display size units from the spec */
+#define DS_PIXELS 0
+#define DS_CM 1
+#define DS_INCHES 2
+#define DS_ASPECT_RATIO 3
+
typedef struct mk_writer mk_writer;
mk_writer *mk_create_writer( const char *filename );
int64_t default_frame_duration,
int64_t timescale,
unsigned width, unsigned height,
- unsigned d_width, unsigned d_height );
+ unsigned d_width, unsigned d_height, int display_size_units );
int mk_start_frame( mk_writer *w );
int mk_add_frame_data( mk_writer *w, const void *data, unsigned size );