+ // Setup custom I/O if redirecting
+ if ( mlt_properties_get_int( properties, "redirect" ) )
+ {
+ int buffer_size = 32768;
+ unsigned char *buffer = av_malloc( buffer_size );
+#if LIBAVFORMAT_VERSION_MAJOR >= 53
+ AVIOContext* io = avio_alloc_context( buffer, buffer_size, 1, properties, NULL, mlt_write, NULL );
+#else
+ ByteIOContext* io = av_alloc_put_byte( buffer, buffer_size, 1, properties, NULL, mlt_write, NULL );
+#endif
+ if ( buffer && io )
+ {
+ oc->pb = io;
+#if LIBAVFORMAT_VERSION_MAJOR >= 53
+ oc->flags |= AVFMT_FLAG_CUSTOM_IO;
+#endif
+ mlt_properties_set_data( properties, "avio_buffer", buffer, buffer_size, av_free, NULL );
+ mlt_properties_set_data( properties, "avio_context", io, 0, av_free, NULL );
+ mlt_events_register( properties, "avformat-write", (mlt_transmitter) write_transmitter );
+ }
+ else
+ {
+ av_free( buffer );
+ mlt_log_error( MLT_CONSUMER_SERVICE(consumer), "failed to setup output redirection\n" );
+ }
+ }