]> git.sesse.net Git - mlt/commitdiff
drop deprecated APIs of libavformat/codec v53
authorDan Dennedy <dan@dennedy.org>
Sat, 14 Jan 2012 22:11:47 +0000 (14:11 -0800)
committerDan Dennedy <dan@dennedy.org>
Sat, 14 Jan 2012 22:11:47 +0000 (14:11 -0800)
src/modules/avformat/consumer_avformat.c
src/modules/avformat/factory.c
src/modules/avformat/producer_avformat.c

index 1db204299ff83c3df13f64f34a34acb22449b351..b0dc61d0391cf7aafb8d29e237220ac1245e7741 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * consumer_avformat.c -- an encoder based on avformat
- * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
+ * Copyright (C) 2003-2012 Ushodaya Enterprises Limited
  * Author: Charles Yates <charles.yates@pandora.be>
+ * Author: Dan Dennedy <dan@dennedy.org>
  * Much code borrowed from ffmpeg.c: Copyright (c) 2000-2003 Fabrice Bellard
  *
  * This library is free software; you can redistribute it and/or
@@ -44,6 +45,7 @@
 #if LIBAVUTIL_VERSION_INT >= ((50<<16)+(8<<8)+0)
 #include <libavutil/pixdesc.h>
 #endif
+#include <libavutil/mathematics.h>
 
 #if LIBAVUTIL_VERSION_INT < (50<<16)
 #define PIX_FMT_RGB32 PIX_FMT_RGBA32
@@ -402,21 +404,33 @@ static void apply_properties( void *obj, mlt_properties properties, int flags )
 {
        int i;
        int count = mlt_properties_count( properties );
+#if LIBAVUTIL_VERSION_INT < ((51<<16)+(12<<8)+0)
        int alloc = 1;
+#endif
 
        for ( i = 0; i < count; i++ )
        {
                const char *opt_name = mlt_properties_get_name( properties, i );
+#if LIBAVUTIL_VERSION_INT >= ((51<<16)+(7<<8)+0)
+               const AVOption *opt = av_opt_find( obj, opt_name, NULL, flags, flags );
+#else
                const AVOption *opt = av_find_opt( obj, opt_name, NULL, flags, flags );
+#endif
 
                // If option not found, see if it was prefixed with a or v (-vb)
                if ( !opt && (
                        ( opt_name[0] == 'v' && ( flags & AV_OPT_FLAG_VIDEO_PARAM ) ) ||
                        ( opt_name[0] == 'a' && ( flags & AV_OPT_FLAG_AUDIO_PARAM ) ) ) )
+#if LIBAVUTIL_VERSION_INT >= ((51<<16)+(7<<8)+0)
+                       opt = av_opt_find( obj, ++opt_name, NULL, flags, flags );
+#else
                        opt = av_find_opt( obj, ++opt_name, NULL, flags, flags );
+#endif
                // Apply option if found
                if ( opt )
-#if LIBAVCODEC_VERSION_INT >= ((52<<16)+(7<<8)+0)
+#if LIBAVUTIL_VERSION_INT >= ((51<<16)+(12<<8)+0)
+                       av_opt_set( obj, opt_name, mlt_properties_get_value( properties, i), 0 );
+#elif LIBAVCODEC_VERSION_INT >= ((52<<16)+(7<<8)+0)
                        av_set_string3( obj, opt_name, mlt_properties_get_value( properties, i), alloc, NULL );
 #elif LIBAVCODEC_VERSION_INT >= ((51<<16)+(59<<8)+0)
                        av_set_string2( obj, opt_name, mlt_properties_get_value( properties, i), alloc );
@@ -435,7 +449,11 @@ static AVStream *add_audio_stream( mlt_consumer consumer, AVFormatContext *oc, A
        mlt_properties properties = MLT_CONSUMER_PROPERTIES( consumer );
 
        // Create a new stream
+#if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(10<<8)+0)
+       AVStream *st = avformat_new_stream( oc, codec );
+#else
        AVStream *st = av_new_stream( oc, oc->nb_streams );
+#endif
 
        // If created, then initialise from properties
        if ( st != NULL ) 
@@ -490,7 +508,10 @@ static AVStream *add_audio_stream( mlt_consumer consumer, AVFormatContext *oc, A
         if ( audio_qscale > QSCALE_NONE )
                {
                        c->flags |= CODEC_FLAG_QSCALE;
-                       c->global_quality = st->quality = FF_QP2LAMBDA * audio_qscale;
+                       c->global_quality = FF_QP2LAMBDA * audio_qscale;
+#if LIBAVFORMAT_VERSION_MAJOR < 53
+                       st->quality = c->global_quality;
+#endif
                }
 
                // Set parameters controlled by MLT
@@ -500,7 +521,11 @@ static AVStream *add_audio_stream( mlt_consumer consumer, AVFormatContext *oc, A
 
                if ( mlt_properties_get( properties, "alang" ) != NULL )
 #if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(43<<8)+0)
+#if LIBAVUTIL_VERSION_INT >= ((51<<16)+(8<<8)+0)
+                       av_dict_set( &oc->metadata, "language", mlt_properties_get( properties, "alang" ), 0 );
+#else
                        av_metadata_set2( &oc->metadata, "language", mlt_properties_get( properties, "alang" ), 0 );
+#endif
 #else
 
                        strncpy( st->language, mlt_properties_get( properties, "alang" ), sizeof( st->language ) );
@@ -553,7 +578,11 @@ static int open_audio( mlt_properties properties, AVFormatContext *oc, AVStream
        avformat_lock();
        
        // Continue if codec found and we can open it
-       if ( codec != NULL && avcodec_open( c, codec ) >= 0 )
+#if LIBAVCODEC_VERSION_INT >= ((53<<16)+(8<<8)+0)
+       if ( codec && avcodec_open2( c, codec, NULL ) >= 0 )
+#else
+       if ( codec && avcodec_open( c, codec ) >= 0 )
+#endif
        {
                // ugly hack for PCM codecs (will be removed ASAP with new PCM
                // support to compute the input frame size in samples
@@ -612,7 +641,11 @@ static AVStream *add_video_stream( mlt_consumer consumer, AVFormatContext *oc, A
        mlt_properties properties = MLT_CONSUMER_PROPERTIES( consumer );
 
        // Create a new stream
+#if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(10<<8)+0)
+       AVStream *st = avformat_new_stream( oc, codec );
+#else
        AVStream *st = av_new_stream( oc, oc->nb_streams );
+#endif
 
        if ( st != NULL ) 
        {
@@ -756,7 +789,10 @@ static AVStream *add_video_stream( mlt_consumer consumer, AVFormatContext *oc, A
                if ( mlt_properties_get_double( properties, "qscale" ) > 0 )
                {
                        c->flags |= CODEC_FLAG_QSCALE;
-                       st->quality = FF_QP2LAMBDA * mlt_properties_get_double( properties, "qscale" );
+                       c->global_quality = FF_QP2LAMBDA * mlt_properties_get_double( properties, "qscale" );
+#if LIBAVFORMAT_VERSION_MAJOR < 53
+                       st->quality = c->global_quality;
+#endif
                }
 
                // Allow the user to override the video fourcc
@@ -949,7 +985,11 @@ static int open_video( mlt_properties properties, AVFormatContext *oc, AVStream
 
        // Open the codec safely
        avformat_lock();
-       int result = codec != NULL && avcodec_open( video_enc, codec ) >= 0;
+#if LIBAVCODEC_VERSION_INT >= ((53<<16)+(8<<8)+0)
+       int result = codec && avcodec_open2( video_enc, codec, NULL ) >= 0;
+#else
+       int result = codec && avcodec_open( video_enc, codec ) >= 0;
+#endif
        avformat_unlock();
        
        return result;
@@ -1190,7 +1230,11 @@ static void *consumer_thread( void *arg )
                                markup[0] = '\0';
                                if ( !strstr( key, ".stream." ) )
 #if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(43<<8)+0)
+#if LIBAVUTIL_VERSION_INT >= ((51<<16)+(8<<8)+0)
+                                       av_dict_set( &oc->metadata, key, mlt_properties_get_value( properties, i ), 0 );
+#else
                                        av_metadata_set2( &oc->metadata, key, mlt_properties_get_value( properties, i ), 0 );
+#endif
 #else
                                        av_metadata_set( &oc->metadata, key, mlt_properties_get_value( properties, i ) );
 #endif
@@ -1269,9 +1313,16 @@ static void *consumer_thread( void *arg )
        mlt_properties_set_int( properties, "channels", total_channels );
 
        // Set the parameters (even though we have none...)
-       if ( av_set_parameters(oc, NULL) >= 0 ) 
+#if LIBAVFORMAT_VERSION_INT < ((53<<16)+(2<<8)+0)
+       if ( av_set_parameters(oc, NULL) >= 0 )
+#endif
        {
+#if LIBAVFORMAT_VERSION_MAJOR >= 53
+               if ( mlt_properties_get( properties, "muxpreload" ) && ! mlt_properties_get( properties, "preload" ) )
+                       mlt_properties_set_double( properties, "preload", mlt_properties_get_double( properties, "muxpreload" ) );
+#else
                oc->preload = ( int )( mlt_properties_get_double( properties, "muxpreload" ) * AV_TIME_BASE );
+#endif
                oc->max_delay= ( int )( mlt_properties_get_double( properties, "muxdelay" ) * AV_TIME_BASE );
 
                // Process properties as AVOptions
@@ -1344,13 +1395,19 @@ static void *consumer_thread( void *arg )
        
                // Write the stream header.
                if ( mlt_properties_get_int( properties, "running" ) )
+#if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(2<<8)+0)
+                       avformat_write_header( oc, NULL );
+#else
                        av_write_header( oc );
+#endif
        }
+#if LIBAVFORMAT_VERSION_INT < ((53<<16)+(2<<8)+0)
        else
        {
                mlt_log_error( MLT_CONSUMER_SERVICE( consumer ), "Invalid output format parameters\n" );
                mlt_properties_set_int( properties, "running", 0 );
        }
+#endif
 
        // Allocate picture
        if ( video_st )
@@ -1660,7 +1717,7 @@ static void *consumer_thread( void *arg )
                                        else 
                                        {
                                                // Set the quality
-                                               output->quality = video_st->quality;
+                                               output->quality = c->global_quality;
 
                                                // Set frame interlace hints
                                                output->interlaced_frame = !mlt_properties_get_int( frame_properties, "progressive" );
index 7676f868b99479e7cc34cf1690c2000bdf7a8436..e7fbb6c0213e4133cc77e19b155cd0c6c13d2843 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * factory.c -- the factory method interfaces
- * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
+ * Copyright (C) 2003-2012 Ushodaya Enterprises Limited
  * Author: Charles Yates <charles.yates@pandora.be>
  *
  * This library is free software; you can redistribute it and/or
@@ -143,7 +143,11 @@ static void add_parameters( mlt_properties params, void *object, int req_flags,
        const AVOption *opt = NULL;
 
        // For each AVOption on the AVClass object
+#if LIBAVUTIL_VERSION_INT >= ((51<<16)+(12<<8)+0)
+       while ( ( opt = av_opt_next( object, opt ) ) )
+#else
        while ( ( opt = av_next_option( object, opt ) ) )
+#endif
        {
                // If matches flags and not a binary option (not supported by Mlt)
                if ( !( opt->flags & req_flags ) || ( opt->type == FF_OPT_TYPE_BINARY ) )
@@ -313,7 +317,11 @@ static mlt_properties avformat_metadata( mlt_service_type type, const char *id,
                // Annotate the yaml properties with AVOptions.
                mlt_properties params = (mlt_properties) mlt_properties_get_data( result, "parameters", NULL );
                AVFormatContext *avformat = avformat_alloc_context();
+#if LIBAVCODEC_VERSION_INT > ((53<<16)+(8<<8)+0)
+               AVCodecContext *avcodec = avcodec_alloc_context3( NULL );
+#else
                AVCodecContext *avcodec = avcodec_alloc_context();
+#endif
                int flags = ( type == consumer_type )? AV_OPT_FLAG_ENCODING_PARAM : AV_OPT_FLAG_DECODING_PARAM;
 
                add_parameters( params, avformat, flags, NULL, NULL );
index 3098be904870f39e00b05f1146368f574fd94344..55c5bdc2eea91326dc7e47c08d36f3dbd25217b1 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * producer_avformat.c -- avformat producer
- * Copyright (C) 2003-2009 Ushodaya Enterprises Limited
+ * Copyright (C) 2003-2012 Ushodaya Enterprises Limited
  * Author: Charles Yates <charles.yates@pandora.be>
  * Author: Dan Dennedy <dan@dennedy.org>
  * Much code borrowed from ffmpeg.c: Copyright (c) 2000-2003 Fabrice Bellard
@@ -45,6 +45,9 @@ const char *avcodec_get_sample_fmt_name(int sample_fmt);
 #if (LIBAVUTIL_VERSION_INT > ((50<<16)+(7<<8)+0))
 #  include <libavutil/pixdesc.h>
 #endif
+#if (LIBAVUTIL_VERSION_INT >= ((51<<16)+(8<<8)+0))
+#  include <libavutil/dict.h>
+#endif
 
 // System header files
 #include <stdlib.h>
@@ -197,11 +200,18 @@ mlt_producer producer_avformat_init( mlt_profile profile, const char *service, c
                                {
                                        // Close the file to release resources for large playlists - reopen later as needed
                                        avformat_lock();
+#if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(17<<8)+0)
+                                       if ( self->audio_format )
+                                               avformat_close_input( &self->audio_format );
+                                       if ( self->video_format )
+                                               avformat_close_input( &self->video_format );
+#else
                                        if ( self->audio_format )
                                                av_close_input_file( self->audio_format );
-                                       self->audio_format = NULL;
                                        if ( self->video_format )
                                                av_close_input_file( self->video_format );
+#endif
+                                       self->audio_format = NULL;
                                        self->video_format = NULL;
                                        avformat_unlock();
                                }
@@ -266,7 +276,11 @@ static mlt_properties find_default_streams( producer_avformat self )
 {
        int i;
        char key[200];
+#if LIBAVUTIL_VERSION_INT >= ((51<<16)+(8<<8)+0)
+       AVDictionaryEntry *tag = NULL;
+#else
        AVMetadataTag *tag = NULL;
+#endif
        AVFormatContext *context = self->video_format;
        mlt_properties meta_media = MLT_PRODUCER_PROPERTIES( self->parent );
 
@@ -315,7 +329,11 @@ static mlt_properties find_default_streams( producer_avformat self )
                                mlt_properties_set_double( meta_media, key, (double) codec_context->time_base.den /
                                                                                   ( codec_context->time_base.num == 0 ? 1 : codec_context->time_base.num ) );
                                snprintf( key, sizeof(key), "meta.media.%d.codec.pix_fmt", i );
+#if LIBAVUTIL_VERSION_INT >= ((51<<16)+(3<<8)+0)
+                               mlt_properties_set( meta_media, key, av_get_pix_fmt_name( codec_context->pix_fmt ) );
+#else
                                mlt_properties_set( meta_media, key, avcodec_get_pix_fmt_name( codec_context->pix_fmt ) );
+#endif
                                snprintf( key, sizeof(key), "meta.media.%d.codec.sample_aspect_ratio", i );
                                mlt_properties_set_double( meta_media, key, av_q2d( codec_context->sample_aspect_ratio ) );
 #if LIBAVCODEC_VERSION_INT > ((52<<16)+(28<<8)+0)
@@ -378,7 +396,11 @@ static mlt_properties find_default_streams( producer_avformat self )
 
                // Read Metadata
 #if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(31<<8)+0)
+#if LIBAVUTIL_VERSION_INT >= ((51<<16)+(8<<8)+0)
+               while ( ( tag = av_dict_get( stream->metadata, "", tag, AV_DICT_IGNORE_SUFFIX ) ) )
+#else
                while ( ( tag = av_metadata_get( stream->metadata, "", tag, AV_METADATA_IGNORE_SUFFIX ) ) )
+#endif
                {
                        if ( tag->value && strcmp( tag->value, "" ) && strcmp( tag->value, "und" ) )
                        {
@@ -389,7 +411,11 @@ static mlt_properties find_default_streams( producer_avformat self )
 #endif
        }
 #if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(31<<8)+0)
+#if LIBAVUTIL_VERSION_INT >= ((51<<16)+(8<<8)+0)
+       while ( ( tag = av_dict_get( context->metadata, "", tag, AV_DICT_IGNORE_SUFFIX ) ) )
+#else
        while ( ( tag = av_metadata_get( context->metadata, "", tag, AV_METADATA_IGNORE_SUFFIX ) ) )
+#endif
        {
                if ( tag->value && strcmp( tag->value, "" ) && strcmp( tag->value, "und" ) )
                {
@@ -544,11 +570,15 @@ static double get_aspect_ratio( mlt_properties properties, AVStream *stream, AVC
        return aspect_ratio;
 }
 
+#if LIBAVFORMAT_VERSION_INT > ((53<<16)+(6<<8)+0)
+static char* parse_url( mlt_profile profile, const char* URL, AVInputFormat **format, AVDictionary **params )
+#else
 static char* parse_url( mlt_profile profile, const char* URL, AVInputFormat **format, AVFormatParameters *params )
+#endif
 {
        if ( !URL ) return NULL;
 
-       const char *result = URL;
+       char *result = NULL;
        char *protocol = strdup( URL );
        char *url = strchr( protocol, ':' );
 
@@ -571,6 +601,11 @@ static char* parse_url( mlt_profile profile, const char* URL, AVInputFormat **fo
 
                if ( *format )
                {
+#if LIBAVFORMAT_VERSION_INT > ((53<<16)+(6<<8)+0)
+                       // support for legacy width and height parameters
+                       char *width = NULL;
+                       char *height = NULL;
+#else
                        // These are required by video4linux2 (defaults)
                        params->width = profile->width;
                        params->height = profile->height;
@@ -578,6 +613,7 @@ static char* parse_url( mlt_profile profile, const char* URL, AVInputFormat **fo
                                params->time_base = (AVRational){ profile->frame_rate_den, profile->frame_rate_num };
                        params->channels = 2;
                        params->sample_rate = 48000;
+#endif
 
                        // Parse out params
                        url = strchr( url, '?' );
@@ -596,6 +632,20 @@ static char* parse_url( mlt_profile profile, const char* URL, AVInputFormat **fo
                                        char *t = strchr( value, '&' );
                                        if ( t )
                                                t[0] = 0;
+#if LIBAVFORMAT_VERSION_INT > ((53<<16)+(6<<8)+0)
+                                       // translate old parameters to new av_dict names
+                                       if ( !strcmp( name, "frame_rate" ) )
+                                               av_dict_set( params, "framerate", value, 0 );
+                                       else if ( !strcmp( name, "pix_fmt" ) )
+                                               av_dict_set( params, "pixel_format", value, 0 );
+                                       else if ( !strcmp( name, "width" ) )
+                                               width = strdup( value );
+                                       else if ( !strcmp( name, "height" ) )
+                                               height = strdup( value );
+                                       else
+                                               // generic demux/device option support
+                                               av_dict_set( params, name, value, 0 );
+#else
                                        if ( !strcmp( name, "frame_rate" ) )
                                                params->time_base.den = atoi( value );
                                        else if ( !strcmp( name, "frame_rate_base" ) )
@@ -616,13 +666,32 @@ static char* parse_url( mlt_profile profile, const char* URL, AVInputFormat **fo
                                                params->height = atoi( value );
                                        else if ( !strcmp( name, "standard" ) )
                                                params->standard = strdup( value );
+#endif
                                }
                                free( name );
                                url = strchr( url, '&' );
                        }
+#if LIBAVFORMAT_VERSION_INT > ((53<<16)+(6<<8)+0)
+                       // continued support for legacy width and height parameters
+                       if ( width && height )
+                       {
+                               char *s = malloc( strlen( width ) + strlen( height ) + 2 );
+                               strcpy( s, width );
+                               strcat( s, "x");
+                               strcat( s, height );
+                               av_dict_set( params, "video_size", s, 0 );
+                               free( s );
+                       }
+                       if ( width ) free( width );
+                       if ( height ) free ( height );
+#endif
                }
+               result = strdup( result );
+       }
+       else
+       {
+               result = strdup( URL );
        }
-       result = strdup( result );
        free( protocol );
        return result;
 }
@@ -683,9 +752,15 @@ static int get_basic_info( producer_avformat self, mlt_profile profile, const ch
                self->seekable = av_seek_frame( format, -1, format->start_time, AVSEEK_FLAG_BACKWARD ) >= 0;
                mlt_properties_set_int( properties, "seekable", self->seekable );
                self->dummy_context = format;
+#if LIBAVFORMAT_VERSION_INT > ((53<<16)+(6<<8)+0)
+               self->video_format = NULL;
+               avformat_open_input( &self->video_format, filename, NULL, NULL );
+               avformat_find_stream_info( self->video_format, NULL );
+#else
                av_open_input_file( &self->video_format, filename, NULL, 0, NULL );
+               av_find_stream_info( self->video_format );
+#endif
                format = self->video_format;
-               av_find_stream_info( format );
        }
 
        // Fetch the width, height and aspect ratio
@@ -751,15 +826,26 @@ static int producer_open( producer_avformat self, mlt_profile profile, const cha
 
        // Parse URL
        AVInputFormat *format = NULL;
+#if LIBAVFORMAT_VERSION_INT > ((53<<16)+(6<<8)+0)
+       AVDictionary *params = NULL;
+#else
        AVFormatParameters params;
        memset( &params, 0, sizeof(params) );
+#endif
        char *filename = parse_url( profile, URL, &format, &params );
 
        // Now attempt to open the file or device with filename
+#if LIBAVFORMAT_VERSION_INT > ((53<<16)+(6<<8)+0)
+       error = avformat_open_input( &self->video_format, filename, format, &params ) < 0;
+       if ( error )
+               // If the URL is a network stream URL, then we probably need to open with full URL
+               error = avformat_open_input( &self->video_format, URL, format, &params ) < 0;
+#else
        error = av_open_input_file( &self->video_format, filename, format, 0, &params ) < 0;
        if ( error )
                // If the URL is a network stream URL, then we probably need to open with full URL
                error = av_open_input_file( &self->video_format, URL, format, 0, &params ) < 0;
+#endif
 
        // Set MLT properties onto video AVFormatContext
        if ( !error && self->video_format )
@@ -771,15 +857,23 @@ static int producer_open( producer_avformat self, mlt_profile profile, const cha
 #endif
        }
 
+#if LIBAVFORMAT_VERSION_INT > ((53<<16)+(6<<8)+0)
+       av_dict_free( &params );
+#else
        // Cleanup AVFormatParameters
        if ( params.standard )
                free( (void*) params.standard );
+#endif
 
        // If successful, then try to get additional info
        if ( !error && self->video_format )
        {
                // Get the stream info
+#if LIBAVFORMAT_VERSION_INT > ((53<<16)+(6<<8)+0)
+               error = avformat_find_stream_info( self->video_format, NULL ) < 0;
+#else
                error = av_find_stream_info( self->video_format ) < 0;
+#endif
 
                // Continue if no error
                if ( !error && self->video_format )
@@ -802,13 +896,17 @@ static int producer_open( producer_avformat self, mlt_profile profile, const cha
                                        if ( self->seekable )
                                        {
                                                // And open again for our audio context
-                                               av_open_input_file( &self->audio_format, filename, NULL, 0, NULL );
+#if LIBAVFORMAT_VERSION_INT > ((53<<16)+(6<<8)+0)
+                                               avformat_open_input( &self->audio_format, filename, NULL, NULL );
                                                apply_properties( self->audio_format, properties, AV_OPT_FLAG_DECODING_PARAM );
-#if LIBAVFORMAT_VERSION_MAJOR >= 53
                                                if ( self->audio_format->iformat && self->audio_format->iformat->priv_class && self->audio_format->priv_data )
                                                        apply_properties( self->audio_format->priv_data, properties, AV_OPT_FLAG_DECODING_PARAM );
-#endif
+                                               avformat_find_stream_info( self->audio_format, NULL );
+#else
+                                               av_open_input_file( &self->audio_format, filename, NULL, 0, NULL );
+                                               apply_properties( self->audio_format, properties, AV_OPT_FLAG_DECODING_PARAM );
                                                av_find_stream_info( self->audio_format );
+#endif
                                        }
                                        else
                                        {
@@ -842,7 +940,11 @@ static int producer_open( producer_avformat self, mlt_profile profile, const cha
        if ( self->dummy_context )
        {
                avformat_lock();
+#if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(17<<8)+0)
+               avformat_close_input( &self->dummy_context );
+#else
                av_close_input_file( self->dummy_context );
+#endif
                avformat_unlock();
                self->dummy_context = NULL;
        }
@@ -868,11 +970,18 @@ static void reopen_video( producer_avformat self, mlt_producer producer )
        if ( self->video_codec )
                avcodec_close( self->video_codec );
        self->video_codec = NULL;
+#if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(17<<8)+0)
+       if ( self->dummy_context )
+               avformat_close_input( &self->dummy_context );
+       if ( self->video_format )
+               avformat_close_input( &self->video_format );
+#else
        if ( self->dummy_context )
                av_close_input_file( self->dummy_context );
-       self->dummy_context = NULL;
        if ( self->video_format )
                av_close_input_file( self->video_format );
+#endif
+       self->dummy_context = NULL;
        self->video_format = NULL;
        avformat_unlock();
 
@@ -1036,7 +1145,11 @@ static void get_audio_streams_info( producer_avformat self )
 
                        // If we don't have a codec and we can't initialise it, we can't do much more...
                        avformat_lock( );
+#if LIBAVCODEC_VERSION_INT >= ((53<<16)+(8<<8)+0)
+                       if ( codec && avcodec_open2( codec_context, codec, NULL ) >= 0 )
+#else
                        if ( codec && avcodec_open( codec_context, codec ) >= 0 )
+#endif
                        {
                                self->audio_streams++;
                                self->audio_max_stream = i;
@@ -1678,11 +1791,17 @@ static void apply_properties( void *obj, mlt_properties properties, int flags )
        for ( i = 0; i < count; i++ )
        {
                const char *opt_name = mlt_properties_get_name( properties, i );
+#if LIBAVUTIL_VERSION_INT >= ((51<<16)+(7<<8)+0)
+               const AVOption *opt = av_opt_find( obj, opt_name, NULL, flags, flags );
+#else
                const AVOption *opt = av_find_opt( obj, opt_name, NULL, flags, flags );
+#endif
                if ( opt_name && mlt_properties_get( properties, opt_name ) )
                {
                        if ( opt )
-#if LIBAVCODEC_VERSION_INT >= ((52<<16)+(7<<8)+0)
+#if LIBAVUTIL_VERSION_INT >= ((51<<16)+(12<<8)+0)
+                               av_opt_set( obj, opt_name, mlt_properties_get( properties, opt_name), 0 );
+#elif LIBAVCODEC_VERSION_INT >= ((52<<16)+(7<<8)+0)
                                av_set_string3( obj, opt_name, mlt_properties_get( properties, opt_name), 0, NULL );
 #elif LIBAVCODEC_VERSION_INT >= ((51<<16)+(59<<8)+0)
                                av_set_string2( obj, opt_name, mlt_properties_get( properties, opt_name), 0 );
@@ -1735,7 +1854,11 @@ static int video_codec_init( producer_avformat self, int index, mlt_properties p
 
                // If we don't have a codec and we can't initialise it, we can't do much more...
                avformat_lock( );
+#if LIBAVCODEC_VERSION_INT >= ((53<<16)+(8<<8)+0)
+               if ( codec && avcodec_open2( codec_context, codec, NULL ) >= 0 )
+#else
                if ( codec && avcodec_open( codec_context, codec ) >= 0 )
+#endif
                {
                        // Now store the codec with its destructor
                        self->video_codec = codec_context;
@@ -1986,7 +2109,9 @@ static int seek_audio( producer_avformat self, mlt_position position, double tim
 
 static int sample_bytes( AVCodecContext *context )
 {
-#if LIBAVCODEC_VERSION_MAJOR >= 53
+#if LIBAVUTIL_VERSION_INT >= ((51<<16)+(8<<8)+0)
+       return av_get_bytes_per_sample( context->sample_fmt );
+#elif LIBAVCODEC_VERSION_MAJOR >= 53
        return av_get_bits_per_sample_fmt( context->sample_fmt ) / 8;
 #else
        return av_get_bits_per_sample_format( context->sample_fmt ) / 8;
@@ -2379,7 +2504,11 @@ static int audio_codec_init( producer_avformat self, int index, mlt_properties p
 
                // If we don't have a codec and we can't initialise it, we can't do much more...
                avformat_lock( );
+#if LIBAVCODEC_VERSION_INT >= ((53<<16)+(8<<8)+0)
+               if ( codec && avcodec_open2( codec_context, codec, NULL ) >= 0 )
+#else
                if ( codec && avcodec_open( codec_context, codec ) >= 0 )
+#endif
                {
                        // Now store the codec with its destructor
                        if ( self->audio_codec[ index ] )
@@ -2567,12 +2696,21 @@ static void producer_avformat_close( producer_avformat self )
                avcodec_close( self->video_codec );
        self->video_codec = NULL;
        // Close the file
+#if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(17<<8)+0)
+       if ( self->dummy_context )
+               avformat_close_input( &self->dummy_context );
+       if ( self->seekable && self->audio_format )
+               avformat_close_input( &self->audio_format );
+       if ( self->video_format )
+               avformat_close_input( &self->video_format );
+#else
        if ( self->dummy_context )
                av_close_input_file( self->dummy_context );
        if ( self->seekable && self->audio_format )
                av_close_input_file( self->audio_format );
        if ( self->video_format )
                av_close_input_file( self->video_format );
+#endif
        avformat_unlock();
 #ifdef VDPAU
        vdpau_producer_close( self );