+void reopen_video( producer_avformat self, mlt_producer producer, mlt_properties properties )
+{
+ mlt_service_lock( MLT_PRODUCER_SERVICE( producer ) );
+ pthread_mutex_lock( &self->audio_mutex );
+
+ if ( self->video_codec )
+ {
+ avformat_lock();
+ avcodec_close( self->video_codec );
+ avformat_unlock();
+ }
+ self->video_codec = NULL;
+ 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 );
+ self->video_format = NULL;
+
+ int audio_index = self->audio_index;
+ int video_index = self->video_index;
+
+ mlt_events_block( properties, producer );
+ pthread_mutex_unlock( &self->audio_mutex );
+ pthread_mutex_unlock( &self->video_mutex );
+ producer_open( self, mlt_service_profile( MLT_PRODUCER_SERVICE(producer) ),
+ mlt_properties_get( properties, "resource" ) );
+ pthread_mutex_lock( &self->video_mutex );
+ pthread_mutex_lock( &self->audio_mutex );
+ if ( self->dummy_context )
+ {
+ av_close_input_file( self->dummy_context );
+ self->dummy_context = NULL;
+ }
+ mlt_events_unblock( properties, producer );
+ apply_properties( self->video_format, properties, AV_OPT_FLAG_DECODING_PARAM );
+#if LIBAVFORMAT_VERSION_MAJOR > 52
+ if ( self->video_format->iformat && self->video_format->iformat->priv_class && self->video_format->priv_data )
+ apply_properties( self->video_format->priv_data, properties, AV_OPT_FLAG_DECODING_PARAM );
+#endif
+
+ self->audio_index = audio_index;
+ if ( self->video_format && video_index > -1 )
+ {
+ self->video_index = video_index;
+ video_codec_init( self, video_index, properties );
+ }
+
+ pthread_mutex_unlock( &self->audio_mutex );
+ mlt_service_unlock( MLT_PRODUCER_SERVICE( producer ) );
+}
+