Fix bug in reference frame autoadjustment
authorJames Darnley <james.darnley@gmail.com>
Thu, 9 Jul 2009 18:25:55 +0000 (11:25 -0700)
committerJason Garrett-Glaser <darkshikari@gmail.com>
Thu, 9 Jul 2009 18:25:55 +0000 (11:25 -0700)
For some types of input file, x264 did the adjustment before width/height were known.

x264.c

diff --git a/x264.c b/x264.c
index e79f9ac..91d2ca1 100644 (file)
--- a/x264.c
+++ b/x264.c
@@ -822,24 +822,6 @@ generic_option:
         param->analyse.i_trellis = 0;
     }
 
-    /* Automatically reduce reference frame count to match the user's target level
-     * if the user didn't explicitly set a reference frame count. */
-    if( !b_user_ref )
-    {
-        int mbs = (((param->i_width)+15)>>4) * (((param->i_height)+15)>>4);
-        int i;
-        for( i = 0; x264_levels[i].level_idc != 0; i++ )
-            if( param->i_level_idc == x264_levels[i].level_idc )
-            {
-                while( mbs * 384 * param->i_frame_reference > x264_levels[i].dpb
-                       && param->i_frame_reference > 1 )
-                {
-                    param->i_frame_reference--;
-                }
-                break;
-            }
-    }
-
     /* Apply profile restrictions. */
     if( profile )
     {
@@ -972,6 +954,26 @@ generic_option:
     }
 #endif
 
+
+    /* Automatically reduce reference frame count to match the user's target level
+     * if the user didn't explicitly set a reference frame count. */
+    if( !b_user_ref )
+    {
+        int mbs = (((param->i_width)+15)>>4) * (((param->i_height)+15)>>4);
+        int i;
+        for( i = 0; x264_levels[i].level_idc != 0; i++ )
+            if( param->i_level_idc == x264_levels[i].level_idc )
+            {
+                while( mbs * 384 * param->i_frame_reference > x264_levels[i].dpb
+                       && param->i_frame_reference > 1 )
+                {
+                    param->i_frame_reference--;
+                }
+                break;
+            }
+    }
+
+
     return 0;
 }