[FFmpeg-devel] Proposal: x264_version() function?

Loren Merritt lorenm
Sat Apr 11 16:17:36 CEST 2009


On Sat, 11 Apr 2009, Jason Garrett-Glaser wrote:

> I've been getting more and more reports recently of the following
> situation resulting in broken ffmpeg compilation with x264:
>
> 1.  User has x264 shared library installed (API version 65 or 66).
> 2.  User updates his x264 to API version 67 but doesn't compile it
> with shared.  x264.h is overwritten.
> 3.  User compiles ffmpeg against the new x264.h, but ld links to the old .so.
> 4.  User experiences random errors, segfaults, other brokenness due to
> bad linking.
>
> Proposed solution: new x264 API function:
>
> int x264_version();
>
> which returns the API version number.  Upon initializing the encoder,
> ffmpeg would call this and terminate if it did not match the one
> included in x264.h.  The error message might be something like:
>
> "Error initializing x264 encoder: linked x264 library does not match
> the API version provided in header."

No application-visible change needed.

--Loren Merritt
-------------- next part --------------
commit c0c88360572d5a7a3795067e9fa0603b20fc9377
Author: Loren Merritt <pengvado at akuvian.org>
Date:   Sat Apr 11 14:15:27 2009 +0000

    check for consistency between libx264's version and x264.h's version.
    this should help diagnose broken installs, rather than just crashing.

diff --git a/encoder/encoder.c b/encoder/encoder.c
index 43a9b95..16dfa21 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -616,7 +616,7 @@ static void mbcmp_init( x264_t *h )
 /****************************************************************************
  * x264_encoder_open:
  ****************************************************************************/
-x264_t *x264_encoder_open   ( x264_param_t *param )
+x264_t *x264_encoder_open_internal( x264_param_t *param, int api_version )
 {
     x264_t *h = x264_malloc( sizeof( x264_t ) );
     char buf[1000], *p;
@@ -627,6 +627,14 @@ x264_t *x264_encoder_open   ( x264_param_t *param )
     /* Create a copy of param */
     memcpy( &h->param, param, sizeof( x264_param_t ) );
 
+    if( api_version != X264_BUILD )
+    {
+        x264_log( h, X264_LOG_ERROR, "libx264 version doesn't match header version.\n" );
+        x264_log( h, X264_LOG_ERROR, "Please reinstall libx264 and recompile whatever application you're running it from.\n" );
+        x264_free( h );
+        return NULL;
+    }
+
     if( x264_validate_parameters( h ) < 0 )
     {
         x264_free( h );
diff --git a/x264.h b/x264.h
index 26ac421..5f45337 100644
--- a/x264.h
+++ b/x264.h
@@ -35,7 +35,7 @@
 
 #include <stdarg.h>
 
-#define X264_BUILD 67
+#define X264_BUILD 68
 
 /* x264_t:
  *      opaque handler for encoder */
@@ -413,7 +413,8 @@ int x264_nal_encode( void *, int *, int b_annexeb, x264_nal_t *nal );
 
 /* x264_encoder_open:
  *      create a new encoder handler, all parameters from x264_param_t are copied */
-x264_t *x264_encoder_open   ( x264_param_t * );
+#define x264_encoder_open( param ) x264_encoder_open_internal( param, X264_BUILD )
+x264_t *x264_encoder_open_internal( x264_param_t *, int api_version );
 /* x264_encoder_reconfig:
  *      change encoder options while encoding,
  *      analysis-related parameters from x264_param_t are copied */



More information about the ffmpeg-devel mailing list