[x264-devel] commit: new API function x264_encoder_delayed_frames. (Anton Mitrofanov )

git version control git at videolan.org
Thu Aug 13 23:43:07 CEST 2009


x264 | branch: master | Anton Mitrofanov <BugMaster at narod.ru> | Thu Aug 13 21:40:21 2009 +0000| [42d6b17b439fc90793d19788e7b314e2517c1fc2] | committer: Loren Merritt 

new API function x264_encoder_delayed_frames.
fix x264cli on streams whose total length is less than the encoder latency.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=42d6b17b439fc90793d19788e7b314e2517c1fc2
---

 encoder/encoder.c |   17 +++++++++++++++++
 x264.c            |    7 ++++---
 x264.h            |    6 +++++-
 3 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/encoder/encoder.c b/encoder/encoder.c
index 7b8d2f2..2359e2f 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -2137,3 +2137,20 @@ void    x264_encoder_close  ( x264_t *h )
         x264_free( h->thread[i] );
     }
 }
+
+/****************************************************************************
+ * x264_encoder_delayed_frames:
+ ****************************************************************************/
+int x264_encoder_delayed_frames( x264_t *h )
+{
+    int delayed_frames = 0;
+    int i;
+    for( i=0; i<h->param.i_threads; i++ )
+        delayed_frames += h->thread[i]->b_thread_active;
+    h = h->thread[ h->i_thread_phase % h->param.i_threads ];
+    for( i=0; h->frames.current[i]; i++ )
+        delayed_frames++;
+    for( i=0; h->frames.next[i]; i++ )
+        delayed_frames++;
+    return delayed_frames;
+}
diff --git a/x264.c b/x264.c
index f507385..32e6570 100644
--- a/x264.c
+++ b/x264.c
@@ -1192,13 +1192,14 @@ static int  Encode( x264_param_t *param, cli_opt_t *opt )
             fflush( stderr ); // needed in windows
         }
     }
-    /* Flush delayed B-frames */
-    do {
+    /* Flush delayed frames */
+    while( x264_encoder_delayed_frames( h ) )
+    {
         i_frame_size = Encode_frame( h, opt->hout, NULL );
         if( i_frame_size < 0 )
             return -1;
         i_file += i_frame_size;
-    } while( i_frame_size );
+    }
 
     i_end = x264_mdate();
     x264_picture_clean( &pic );
diff --git a/x264.h b/x264.h
index 1416248..964e093 100644
--- a/x264.h
+++ b/x264.h
@@ -35,7 +35,7 @@
 
 #include <stdarg.h>
 
-#define X264_BUILD 70
+#define X264_BUILD 71
 
 /* x264_t:
  *      opaque handler for encoder */
@@ -431,5 +431,9 @@ int     x264_encoder_encode ( x264_t *, x264_nal_t **, int *, x264_picture_t *,
 /* x264_encoder_close:
  *      close an encoder handler */
 void    x264_encoder_close  ( x264_t * );
+/* x264_encoder_delayed_frames:
+ *      return the number of currently delayed (buffered) frames
+ *      this should be used at the end of the stream, to know when you have all the encoded frames. */
+int     x264_encoder_delayed_frames( x264_t * );
 
 #endif



More information about the x264-devel mailing list