From 6b20e508a7f7110b4c951fbdc4a971cc5c14494d Mon Sep 17 00:00:00 2001 From: =?utf8?q?M=C3=A5ns=20Rullg=C3=A5rd?= Date: Thu, 12 Aug 2004 20:52:24 +0000 Subject: [PATCH] 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 --- core/common.c | 3 +- core/set.h | 8 ++++- encoder/encoder.c | 3 +- encoder/ratecontrol.c | 7 +++- encoder/set.c | 81 +++++++++++++++++++++++++++---------------- x264.c | 1 - x264.h | 3 +- 7 files changed, 70 insertions(+), 36 deletions(-) diff --git a/core/common.c b/core/common.c index 1e3e4c2e..61a78306 100644 --- a/core/common.c +++ b/core/common.c @@ -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; diff --git a/core/set.h b/core/set.h index bfd75e84..185dc8ed 100644 --- a/core/set.h +++ b/core/set.h @@ -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 diff --git a/encoder/encoder.c b/encoder/encoder.c index a3b9481a..9b7d4dfa 100644 --- a/encoder/encoder.c +++ b/encoder/encoder.c @@ -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 diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c index 230a97d2..9e0c8a43 100644 --- a/encoder/ratecontrol.c +++ b/encoder/ratecontrol.c @@ -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); diff --git a/encoder/set.c b/encoder/set.c index 9b4a8de5..6b5162c7 100644 --- a/encoder/set.c +++ b/encoder/set.c @@ -1,5 +1,5 @@ /***************************************************************************** - * 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 */ diff --git a/x264.c b/x264.c index a16cf6b4..4e9e015a 100644 --- a/x264.c +++ b/x264.c @@ -73,7 +73,6 @@ int main( int argc, char **argv ) #endif x264_param_default( ¶m ); - param.f_fps = 25.0; /* Parse command line */ if( Parse( argc, argv, ¶m, &fin, &fout, &b_decompress ) < 0 ) diff --git a/x264.h b/x264.h index 6d17d940..2cfbbd65 100644 --- a/x264.h +++ b/x264.h @@ -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 */ -- 2.47.3