]> granicus.if.org Git - libx264/commitdiff
Include timing info in VUI.
authorMåns Rullgård <mru@mru.ath.cx>
Thu, 12 Aug 2004 20:52:24 +0000 (20:52 +0000)
committerMåns Rullgård <mru@mru.ath.cx>
Thu, 12 Aug 2004 20:52:24 +0000 (20:52 +0000)
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
core/set.h
encoder/encoder.c
encoder/ratecontrol.c
encoder/set.c
x264.c
x264.h

index 1e3e4c2eb3c3fe0bbd9bd41cdae5f67145012134..61a78306e4360ee6ecc014b52713dc14b5564394 100644 (file)
@@ -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;
index bfd75e847994d8bc2b0ec86b00c754939d7f9d87..185dc8ed08f90c87ccf8d0d6109d9f7839a53989 100644 (file)
@@ -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
index a3b9481a6205c451629ce72a29a4090c2f41e05d..9b7d4dfa4815f319627a86b6412507dd307db778 100644 (file)
@@ -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
index 230a97d2b6795192a50a92b9fe1cc5127fe738a6..9e0c8a4372240a6103f655808493ca1b51eb7d05 100644 (file)
@@ -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);
index 9b4a8de5873008db55debcdabcadd85642187733..6b5162c7bc8005002e06af69510d464e3815558d 100644 (file)
@@ -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 a16cf6b42bf273bf836bfce3b14cc7efbe50ae18..4e9e015a1faf9390f94b7f6387cd4815e3f2306a 100644 (file)
--- a/x264.c
+++ b/x264.c
@@ -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 )
diff --git a/x264.h b/x264.h
index 6d17d9408dcc4b061fc20b19b52c2ce7dbf766a1..2cfbbd65dbed50d745a9d9eae916191c469543b9 100644 (file)
--- 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 */