Commit 6b20e508 authored by Måns Rullgård's avatar Måns Rullgård

Include timing info in VUI.

Change frame rate from float to fraction (sorry for the inconvenience).


git-svn-id: svn://svn.videolan.org/x264/trunk@27 df754926-b1dd-0310-bc7b-ec298dee348c
parent 2b3cd6c6
......@@ -57,7 +57,8 @@ void x264_param_default( x264_param_t *param )
param->i_height = 0;
param->vui.i_sar_width = 0;
param->vui.i_sar_height= 0;
param->f_fps = 25.0;
param->i_fps_num = 25;
param->i_fps_den = 1;
/* Encoder parameters */
param->i_frame_reference = 1;
......
......@@ -74,11 +74,17 @@ typedef struct
int b_vui;
struct
{
int b_aspect_ratio_info_present;
int i_sar_width;
int i_sar_height;
int b_timing_info_present;
int i_num_units_in_tick;
int i_time_scale;
int b_fixed_frame_rate;
/* FIXME to complete */
} vui;
} x264_sps_t;
typedef struct
......
......@@ -1306,6 +1306,7 @@ void x264_encoder_close ( x264_t *h )
const int i_count = h->stat.i_slice_count[SLICE_TYPE_I] +
h->stat.i_slice_count[SLICE_TYPE_P] +
h->stat.i_slice_count[SLICE_TYPE_B];
float fps = (float) h->param.i_fps_num / h->param.i_fps_den;
fprintf( stderr, "x264: overall PSNR Mean Y:%5.2f U:%5.2f V:%5.2f Avg:%5.2f Global:%5.2f kb/s:%.1f fps:%.3f\n",
(h->stat.f_psnr_mean_y[SLICE_TYPE_I] + h->stat.f_psnr_mean_y[SLICE_TYPE_P] + h->stat.f_psnr_mean_y[SLICE_TYPE_B]) / i_count,
......@@ -1316,7 +1317,7 @@ void x264_encoder_close ( x264_t *h )
x264_psnr( h->stat.i_sqe_global[SLICE_TYPE_I] + h->stat.i_sqe_global[SLICE_TYPE_P]+ h->stat.i_sqe_global[SLICE_TYPE_B],
i_count * i_yuv_size ),
h->param.f_fps * 8*(h->stat.i_slice_size[SLICE_TYPE_I]+h->stat.i_slice_size[SLICE_TYPE_P]+h->stat.i_slice_size[SLICE_TYPE_B]) / i_count / 1024,
fps * 8*(h->stat.i_slice_size[SLICE_TYPE_I]+h->stat.i_slice_size[SLICE_TYPE_P]+h->stat.i_slice_size[SLICE_TYPE_B]) / i_count / 1024,
(double)1000000.0 * (double)i_count / (double)i_mtime_encode_frame );
}
#endif
......
......@@ -74,7 +74,12 @@ int x264_ratecontrol_new( x264_t *h )
memset(rc, 0, sizeof(*rc));
rc->fps = h->param.f_fps > 0.1 ? h->param.f_fps : 25.0f;
/* FIXME: use integers */
if(h->param.i_fps_num > 0 && h->param.i_fps_den > 0)
rc->fps = (float) h->param.i_fps_num / h->param.i_fps_den;
else
rc->fps = 25.0;
rc->gop_size = h->param.i_iframe;
rc->bitrate = h->param.i_bitrate * 1000;
rc->nmb = ((h->param.i_width + 15) / 16) * ((h->param.i_height + 15) / 16);
......
/*****************************************************************************
* set: h264 encoder (SPS and SPS init and write)
* set: h264 encoder (SPS and PPS init and write)
*****************************************************************************
* Copyright (C) 2003 Laurent Aimar
* $Id: set.c,v 1.1 2004/06/03 19:27:08 fenrir Exp $
......@@ -105,6 +105,8 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param )
sps->crop.i_bottom = 0;
}
sps->b_vui = 0;
if( param->vui.i_sar_width > 0 && param->vui.i_sar_height > 0 )
{
int w = param->vui.i_sar_width;
......@@ -130,25 +132,32 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param )
if( w == 0 || h == 0 )
{
fprintf( stderr, "x264: cannot create valid sample aspect ratio\n" );
sps->b_vui = 0;
sps->vui.b_aspect_ratio_info_present = 0;
}
else if( w == h )
{
fprintf( stderr, "x264: no need for a SAR\n" );
sps->b_vui = 0;
sps->vui.b_aspect_ratio_info_present = 0;
}
else
{
fprintf( stderr, "x264: using SAR=%d/%d\n", w, h );
sps->b_vui = 1;
sps->vui.b_aspect_ratio_info_present = 1;
sps->vui.i_sar_width = w;
sps->vui.i_sar_height= h;
}
}
else
sps->b_vui |= sps->vui.b_aspect_ratio_info_present;
if( param->i_fps_num > 0 && param->i_fps_den > 0)
{
sps->b_vui = 0;
sps->vui.b_timing_info_present = 1;
sps->vui.i_num_units_in_tick = param->i_fps_den;
/* only frame pictures supported for now, so double time_scale */
sps->vui.i_time_scale = param->i_fps_num * 2;
sps->vui.b_fixed_frame_rate = 1;
}
sps->b_vui |= sps->vui.b_timing_info_present;
}
......@@ -207,30 +216,42 @@ void x264_sps_write( bs_t *s, x264_sps_t *sps )
bs_write( s, 1, sps->b_vui );
if( sps->b_vui )
{
int i;
static const struct { int w, h; int sar; } sar[] =
{
{ 1, 1, 1 }, { 12, 11, 2 }, { 10, 11, 3 }, { 16, 11, 4 },
{ 40, 33, 5 }, { 24, 11, 6 }, { 20, 11, 7 }, { 32, 11, 8 },
{ 80, 33, 9 }, { 18, 11, 10}, { 15, 11, 11}, { 64, 33, 12},
{ 160,99, 13}, { 0, 0, -1 }
};
bs_write1( s, 1 ); /* aspect_ratio_info_present_flag */
for( i = 0; sar[i].sar != -1; i++ )
{
if( sar[i].w == sps->vui.i_sar_width && sar[i].h == sps->vui.i_sar_height )
break;
}
if( sar[i].sar != -1 )
{
bs_write( s, 8, sar[i].sar );
}
else
{
bs_write( s, 8, 255); /* aspect_ration_idc (extented) */
bs_write( s, 16, sps->vui.i_sar_width );
bs_write( s, 16, sps->vui.i_sar_height );
}
bs_write1( s, sps->vui.b_aspect_ratio_info_present );
if( sps->vui.b_aspect_ratio_info_present )
{
int i;
static const struct { int w, h; int sar; } sar[] =
{
{ 1, 1, 1 }, { 12, 11, 2 }, { 10, 11, 3 }, { 16, 11, 4 },
{ 40, 33, 5 }, { 24, 11, 6 }, { 20, 11, 7 }, { 32, 11, 8 },
{ 80, 33, 9 }, { 18, 11, 10}, { 15, 11, 11}, { 64, 33, 12},
{ 160,99, 13}, { 0, 0, -1 }
};
for( i = 0; sar[i].sar != -1; i++ )
{
if( sar[i].w == sps->vui.i_sar_width &&
sar[i].h == sps->vui.i_sar_height )
break;
}
if( sar[i].sar != -1 )
{
bs_write( s, 8, sar[i].sar );
}
else
{
bs_write( s, 8, 255); /* aspect_ration_idc (extented) */
bs_write( s, 16, sps->vui.i_sar_width );
bs_write( s, 16, sps->vui.i_sar_height );
}
}
bs_write1( s, sps->vui.b_timing_info_present );
if( sps->vui.b_timing_info_present )
{
bs_write( s, 32, sps->vui.i_num_units_in_tick );
bs_write( s, 32, sps->vui.i_time_scale );
bs_write1( s, sps->vui.b_fixed_frame_rate );
}
bs_write1( s, 0 ); /* overscan_info_present_flag */
......
......@@ -73,7 +73,6 @@ int main( int argc, char **argv )
#endif
x264_param_default( &param );
param.f_fps = 25.0;
/* Parse command line */
if( Parse( argc, argv, &param, &fin, &fout, &b_decompress ) < 0 )
......
......@@ -88,7 +88,8 @@ typedef struct
int i_sar_width;
} vui;
float f_fps; /* Used for rate control only */
int i_fps_num;
int i_fps_den;
/* Bitstream parameters */
int i_frame_reference; /* Maximum number of reference frames */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment