]> granicus.if.org Git - libx264/commitdiff
adjust bitstream buffer sizes for very large frames
authorLoren Merritt <pengvado@videolan.org>
Sat, 24 Mar 2007 12:58:27 +0000 (12:58 +0000)
committerLoren Merritt <pengvado@videolan.org>
Sat, 24 Mar 2007 12:58:27 +0000 (12:58 +0000)
git-svn-id: svn://svn.videolan.org/x264/trunk@635 df754926-b1dd-0310-bc7b-ec298dee348c

encoder/encoder.c
x264.c

index a5eacff20c695c3c15087ebecfb7517e7ab81c03..e82445f903e85578b85a8e0407101b0dc0631a42 100644 (file)
@@ -676,9 +676,9 @@ x264_t *x264_encoder_open   ( x264_param_t *param )
              param->cpu&X264_CPU_ALTIVEC ? "Altivec " : "" );
 
     h->out.i_nal = 0;
-    h->out.i_bitstream = X264_MAX( 1000000, h->param.i_width * h->param.i_height * 1.7
-        * ( h->param.rc.i_rc_method == X264_RC_ABR ? pow( 0.5, h->param.rc.i_qp_min )
-          : pow( 0.5, h->param.rc.i_qp_constant ) * X264_MAX( 1, h->param.rc.f_ip_factor )));
+    h->out.i_bitstream = X264_MAX( 1000000, h->param.i_width * h->param.i_height * 4
+        * ( h->param.rc.i_rc_method == X264_RC_ABR ? pow( 0.95, h->param.rc.i_qp_min )
+          : pow( 0.95, h->param.rc.i_qp_constant ) * X264_MAX( 1, h->param.rc.f_ip_factor )));
 
     h->thread[0] = h;
     h->i_thread_num = 0;
diff --git a/x264.c b/x264.c
index 7718a06664582c9d5dca1f8cf35bb4ca2e7b6bb0..5fb6dc967d17271df48995a6fcd7de53c46e41d5 100644 (file)
--- a/x264.c
+++ b/x264.c
@@ -46,8 +46,8 @@
 #include "x264.h"
 #include "muxers.h"
 
-#define DATA_MAX 3000000
-uint8_t data[DATA_MAX];
+uint8_t *mux_buffer = NULL;
+int mux_buffer_size = 0;
 
 /* Ctrl-C handler */
 static int     b_ctrl_c = 0;
@@ -729,17 +729,17 @@ static int  Encode_frame( x264_t *h, hnd_t hout, x264_picture_t *pic )
     for( i = 0; i < i_nal; i++ )
     {
         int i_size;
-        int i_data;
 
-        i_data = DATA_MAX;
-        if( ( i_size = x264_nal_encode( data, &i_data, 1, &nal[i] ) ) > 0 )
+        if( mux_buffer_size < nal[i].i_payload * 3/2 + 4 )
         {
-            i_file += p_write_nalu( hout, data, i_size );
-        }
-        else if( i_size < 0 )
-        {
-            fprintf( stderr, "x264 [error]: need to increase buffer size (size=%d)\n", -i_size );
+            mux_buffer_size = nal[i].i_payload * 2 + 4;
+            x264_free( mux_buffer );
+            mux_buffer = x264_malloc( mux_buffer_size );
         }
+
+        i_size = mux_buffer_size;
+        x264_nal_encode( mux_buffer, &i_size, 1, &nal[i] );
+        i_file += p_write_nalu( hout, mux_buffer, i_size );
     }
     if (i_nal)
         p_set_eop( hout, &pic_out );