[x264-devel] Fix deprecation in libavformat usage

Steven Walters git at videolan.org
Sun Jul 10 06:11:02 CEST 2011


x264 | branch: master | Steven Walters <kemuri9 at gmail.com> | Sat Jun 18 14:12:34 2011 -0400| [073f081762b78501e57c6bc2667c004858739edf] | committer: Jason Garrett-Glaser

Fix deprecation in libavformat usage
Replace av_open_input_file with avformat_open_input. Now requires libavformat 53.2.0 or newer.

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

 configure    |   12 ++++--------
 input/lavf.c |   20 +++++++++-----------
 2 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/configure b/configure
index 16007e0..d539afe 100755
--- a/configure
+++ b/configure
@@ -744,15 +744,11 @@ if [ "$lavf" = "auto" ] ; then
         done
     fi
     LAVF_LIBS="-L. $LAVF_LIBS"
-    if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" "avcodec_decode_video2(0,0,0,0);" ; then
-        if cpp_check libavcodec/avcodec.h "$LAVF_CFLAGS $LAVF_LIBS" "LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52,64,0)" ; then
-            if [ "$swscale" = "yes" ]; then
-                lavf="yes"
-            else
-                echo "Warning: libavformat is not supported without swscale support"
-            fi
+    if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" "avformat_open_input(0,0,0,0);" ; then
+        if [ "$swscale" = "yes" ]; then
+            lavf="yes"
         else
-            echo "Warning: libavcodec is too old, update to ffmpeg r22735+"
+            echo "Warning: libavformat is not supported without swscale support"
         fi
     fi
 fi
diff --git a/input/lavf.c b/input/lavf.c
index dc9fe55..424d3cb 100644
--- a/input/lavf.c
+++ b/input/lavf.c
@@ -29,6 +29,7 @@
 #undef DECLARE_ALIGNED
 #include <libavformat/avformat.h>
 #include <libavutil/pixdesc.h>
+#include <libavutil/dict.h>
 
 typedef struct
 {
@@ -136,16 +137,13 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
     if( !strcmp( psz_filename, "-" ) )
         psz_filename = "pipe:";
 
-    /* if resolution was passed in, parse it and colorspace into parameters. this allows raw video support */
-    AVFormatParameters *param = NULL;
+    /* if resolution was passed in, place it and colorspace into options. this allows raw video support */
+    AVDictionary *options = NULL;
     if( opt->resolution )
     {
-        param = calloc( 1, sizeof(AVFormatParameters) );
-        if( !param )
-            return -1;
-        sscanf( opt->resolution, "%dx%d", &param->width, &param->height );
-        param->pix_fmt = opt->colorspace ? av_get_pix_fmt( opt->colorspace ) : PIX_FMT_YUV420P;
-        FAIL_IF_ERROR( param->pix_fmt == PIX_FMT_NONE, "unsupported colorspace: %s\n", opt->colorspace );
+        av_dict_set( &options, "video_size", opt->resolution, 0 );
+        const char *csp = opt->colorspace ? opt->colorspace : av_get_pix_fmt_name( PIX_FMT_YUV420P );
+        av_dict_set( &options, "pixel_format", csp, 0 );
     }
 
     /* specify the input format. this is helpful when lavf fails to guess */
@@ -153,9 +151,9 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
     if( opt->format )
         FAIL_IF_ERROR( !(format = av_find_input_format( opt->format )), "unknown file format: %s\n", opt->format );
 
-    FAIL_IF_ERROR( av_open_input_file( &h->lavf, psz_filename, format, 0, param ), "could not open input file\n" )
-    if( param )
-        free( param );
+    FAIL_IF_ERROR( avformat_open_input( &h->lavf, psz_filename, format, &options ), "could not open input file\n" )
+    if( options )
+        av_dict_free( &options );
     FAIL_IF_ERROR( av_find_stream_info( h->lavf ) < 0, "could not find input stream info\n" )
 
     int i = 0;



More information about the x264-devel mailing list