]> git.sesse.net Git - mlt/blobdiff - src/melt/melt.c
add define MELT_NOSDL to not use SDL_main()
[mlt] / src / melt / melt.c
index 9d6df7b74afda098a7c2636ed2245a22174716dc..c125a72e511364594856cb46e652b90551bc456d 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * melt.c -- MLT command line utility
- * Copyright (C) 2002-2010 Ushodaya Enterprises Limited
+ * Copyright (C) 2002-2012 Ushodaya Enterprises Limited
  * Authors: Charles Yates <charles.yates@pandora.be>
  *          Dan Dennedy <dan@dennedy.org>
  *
 #include <sched.h>
 #include <libgen.h>
 #include <limits.h>
+#include <unistd.h>
 
 #include <framework/mlt.h>
 
-#ifdef __DARWIN__
+#if (defined(__DARWIN__) || defined(WIN32)) && !defined(MELT_NOSDL)
 #include <SDL.h>
 #endif
 
@@ -42,6 +43,8 @@ static void transport_action( mlt_producer producer, char *value )
        mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
        mlt_multitrack multitrack = mlt_properties_get_data( properties, "multitrack", NULL );
        mlt_consumer consumer = mlt_properties_get_data( properties, "transport_consumer", NULL );
+       mlt_properties jack = mlt_properties_get_data( MLT_CONSUMER_PROPERTIES( consumer ), "jack_filter", NULL );
+       mlt_position position = mlt_producer_position( producer );
 
        mlt_properties_set_int( properties, "stats_off", 1 );
 
@@ -50,11 +53,16 @@ static void transport_action( mlt_producer producer, char *value )
                switch( value[ 0 ] )
                {
                        case 'q':
+                       case 'Q':
                                mlt_properties_set_int( properties, "done", 1 );
+                               mlt_events_fire( jack, "jack-stop", NULL );
                                break;
                        case '0':
+                               position = 0;
                                mlt_producer_set_speed( producer, 1 );
-                               mlt_producer_seek( producer, 0 );
+                               mlt_producer_seek( producer, position );
+                               mlt_consumer_purge( consumer );
+                               mlt_events_fire( jack, "jack-seek", &position, NULL );
                                break;
                        case '1':
                                mlt_producer_set_speed( producer, -10 );
@@ -70,10 +78,15 @@ static void transport_action( mlt_producer producer, char *value )
                                break;
                        case '5':
                                mlt_producer_set_speed( producer, 0 );
+                               mlt_consumer_purge( consumer );
+                               mlt_events_fire( jack, "jack-stop", NULL );
                                break;
                        case '6':
                        case ' ':
-                               mlt_producer_set_speed( producer, 1 );
+                               if ( !jack || mlt_producer_get_speed( producer ) != 0 )
+                                       mlt_producer_set_speed( producer, 1 );
+                               mlt_consumer_purge( consumer );
+                               mlt_events_fire( jack, "jack-start", NULL );
                                break;
                        case '7':
                                mlt_producer_set_speed( producer, 2 );
@@ -92,11 +105,11 @@ static void transport_action( mlt_producer producer, char *value )
                                        fprintf( stderr, "\n" );
                                        for ( i = 0; 1; i ++ )
                                        {
-                                               mlt_position time = mlt_multitrack_clip( multitrack, mlt_whence_relative_start, i );
-                                               if ( time == last )
+                                               position = mlt_multitrack_clip( multitrack, mlt_whence_relative_start, i );
+                                               if ( position == last )
                                                        break;
-                                               last = time;
-                                               fprintf( stderr, "%d: %d\n", i, (int)time );
+                                               last = position;
+                                               fprintf( stderr, "%d: %d\n", i, (int)position );
                                        }
                                }
                                break;
@@ -104,54 +117,74 @@ static void transport_action( mlt_producer producer, char *value )
                        case 'g':
                                if ( multitrack != NULL )
                                {
-                                       mlt_position time = mlt_multitrack_clip( multitrack, mlt_whence_relative_current, 0 );
-                                       mlt_producer_seek( producer, time );
+                                       position = mlt_multitrack_clip( multitrack, mlt_whence_relative_current, 0 );
+                                       mlt_producer_seek( producer, position );
+                                       mlt_consumer_purge( consumer );
+                                       mlt_events_fire( jack, "jack-seek", &position, NULL );
                                }
                                break;
                        case 'H':
                                if ( producer != NULL )
                                {
-                                       mlt_position position = mlt_producer_position( producer );
-                                       mlt_producer_seek( producer, position - ( mlt_producer_get_fps( producer ) * 60 ) );
+                                       position -= mlt_producer_get_fps( producer ) * 60;
+                                       mlt_consumer_purge( consumer );
+                                       mlt_producer_seek( producer, position );
+                                       mlt_events_fire( jack, "jack-seek", &position, NULL );
                                }
                                break;
                        case 'h':
                                if ( producer != NULL )
                                {
-                                       mlt_position position = mlt_producer_position( producer );
+                                       position--;
                                        mlt_producer_set_speed( producer, 0 );
-                                       mlt_producer_seek( producer, position - 1 );
+                                       mlt_consumer_purge( consumer );
+                                       mlt_producer_seek( producer, position );
+                                       mlt_events_fire( jack, "jack-stop", NULL );
+                                       mlt_events_fire( jack, "jack-seek", &position, NULL );
                                }
                                break;
                        case 'j':
                                if ( multitrack != NULL )
                                {
-                                       mlt_position time = mlt_multitrack_clip( multitrack, mlt_whence_relative_current, 1 );
-                                       mlt_producer_seek( producer, time );
+                                       position = mlt_multitrack_clip( multitrack, mlt_whence_relative_current, 1 );
+                                       mlt_consumer_purge( consumer );
+                                       mlt_producer_seek( producer, position );
+                                       mlt_events_fire( jack, "jack-seek", &position, NULL );
                                }
                                break;
                        case 'k':
                                if ( multitrack != NULL )
                                {
-                                       mlt_position time = mlt_multitrack_clip( multitrack, mlt_whence_relative_current, -1 );
-                                       mlt_producer_seek( producer, time );
+                                       position = mlt_multitrack_clip( multitrack, mlt_whence_relative_current, -1 );
+                                       mlt_consumer_purge( consumer );
+                                       mlt_producer_seek( producer, position );
+                                       mlt_events_fire( jack, "jack-seek", &position, NULL );
                                }
                                break;
                        case 'l':
                                if ( producer != NULL )
                                {
-                                       mlt_position position = mlt_producer_position( producer );
+                                       position++;
+                                       mlt_consumer_purge( consumer );
                                        if ( mlt_producer_get_speed( producer ) != 0 )
+                                       {
                                                mlt_producer_set_speed( producer, 0 );
+                                               mlt_events_fire( jack, "jack-stop", NULL );
+                                       }
                                        else
-                                               mlt_producer_seek( producer, position + 1 );
+                                       {
+                                               mlt_producer_seek( producer, position );
+                                               mlt_events_fire( jack, "jack-seek", &position, NULL );
+                                       }
                                }
                                break;
                        case 'L':
                                if ( producer != NULL )
                                {
-                                       mlt_position position = mlt_producer_position( producer );
-                                       mlt_producer_seek( producer, position + ( mlt_producer_get_fps( producer ) * 60 ) );
+                                       position += mlt_producer_get_fps( producer ) * 60;
+                                       mlt_consumer_purge( consumer );
+                                       mlt_producer_seek( producer, position );
+                                       mlt_events_fire( jack, "jack-seek", &position, NULL );
                                }
                                break;
                }
@@ -162,6 +195,53 @@ static void transport_action( mlt_producer producer, char *value )
        mlt_properties_set_int( properties, "stats_off", 0 );
 }
 
+static void on_jack_started( mlt_properties owner, mlt_consumer consumer, mlt_position *position )
+{
+       mlt_producer producer = mlt_properties_get_data( MLT_CONSUMER_PROPERTIES(consumer), "transport_producer", NULL );
+       if ( producer )
+       {
+               if ( mlt_producer_get_speed( producer ) != 0 )
+               {
+                       mlt_properties jack = mlt_properties_get_data( MLT_CONSUMER_PROPERTIES( consumer ), "jack_filter", NULL );
+                       mlt_events_fire( jack, "jack-stop", NULL );
+               }
+               else
+               {
+                       mlt_producer_set_speed( producer, 1 );
+                       mlt_consumer_purge( consumer );
+                       mlt_producer_seek( producer, *position );
+                       mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( consumer ), "refresh", 1 );
+               }
+       }
+}
+
+static void on_jack_stopped( mlt_properties owner, mlt_consumer consumer, mlt_position *position )
+{
+       mlt_producer producer = mlt_properties_get_data( MLT_CONSUMER_PROPERTIES(consumer), "transport_producer", NULL );
+       if ( producer )
+       {
+               mlt_producer_set_speed( producer, 0 );
+               mlt_consumer_purge( consumer );
+               mlt_producer_seek( producer, *position );
+               mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( consumer ), "refresh", 1 );
+       }
+}
+
+static void setup_jack_transport( mlt_consumer consumer, mlt_profile profile )
+{
+       mlt_properties properties = MLT_CONSUMER_PROPERTIES( consumer );
+       mlt_filter jack = mlt_factory_filter( profile, "jackrack", NULL );
+       mlt_properties jack_properties = MLT_FILTER_PROPERTIES(jack);
+
+       mlt_service_attach( MLT_CONSUMER_SERVICE(consumer), jack );
+       mlt_properties_set_int( properties, "audio_off", 1 );
+       mlt_properties_set_data( properties, "jack_filter", jack, 0, (mlt_destructor) mlt_filter_close, NULL );
+//     mlt_properties_set( jack_properties, "out_1", "system:playback_1" );
+//     mlt_properties_set( jack_properties, "out_2", "system:playback_2" );
+       mlt_events_listen( jack_properties, consumer, "jack-started", (mlt_listener) on_jack_started );
+       mlt_events_listen( jack_properties, consumer, "jack-stopped", (mlt_listener) on_jack_stopped );
+}
+
 static mlt_consumer create_consumer( mlt_profile profile, char *id )
 {
        char *myid = id ? strdup( id ) : NULL;
@@ -179,10 +259,52 @@ static mlt_consumer create_consumer( mlt_profile profile, char *id )
        return consumer;
 }
 
-static void load_consumer( mlt_consumer &consumer, int argc, const char **argv )
+static void load_consumer( mlt_consumer *consumer, mlt_profile profile, int argc, char **argv )
 {
        int i;
+       int multi = 0;
+
        for ( i = 1; i < argc; i ++ )
+               multi += !strcmp( argv[ i ], "-consumer" );
+
+       if ( multi > 1 )
+       {
+               // If there is more than one -consumer use the 'multi' consumer.
+               int k = 0;
+               char key[20];
+
+               if ( *consumer )
+                       mlt_consumer_close( *consumer );
+               *consumer = create_consumer( profile, "multi" );
+               mlt_properties properties = MLT_CONSUMER_PROPERTIES( *consumer );
+               for ( i = 1; i < argc; i ++ )
+               {
+                       if ( !strcmp( argv[ i ], "-consumer" ) && argv[ i + 1 ])
+                       {
+                               // Create a properties object for each sub-consumer
+                               mlt_properties new_props = mlt_properties_new();
+                               snprintf( key, sizeof(key), "%d", k++ );
+                               mlt_properties_set_data( properties, key, new_props, 0,
+                                       (mlt_destructor) mlt_properties_close, NULL );
+                               if ( strchr( argv[i + 1], ':' ) )
+                               {
+                                       char *temp = strdup( argv[++i] );
+                                       char *service = temp;
+                                       char *target = strchr( temp, ':' );
+                                       *target++ = 0;
+                                       mlt_properties_set( new_props, "mlt_service", service );
+                                       mlt_properties_set( new_props, "target", target );
+                               }
+                               else
+                               {
+                                       mlt_properties_set( new_props, "mlt_service", argv[ ++i ] );
+                               }
+                               while ( argv[ i + 1 ] && strchr( argv[ i + 1 ], '=' ) )
+                                       mlt_properties_parse( new_props, argv[ ++ i ] );
+                       }
+               }
+       }
+       else for ( i = 1; i < argc; i ++ )
        {
                if ( !strcmp( argv[ i ], "-consumer" ) )
                {
@@ -192,14 +314,14 @@ static void load_consumer( mlt_consumer &consumer, int argc, const char **argv )
                        if ( *consumer )
                        {
                                mlt_properties properties = MLT_CONSUMER_PROPERTIES( *consumer );
-                               while ( argv[ i + 1 ] != NULL && strstr( argv[ i + 1 ], "=" ) )
+                               while ( argv[ i + 1 ] != NULL && strchr( argv[ i + 1 ], '=' ) )
                                        mlt_properties_parse( properties, argv[ ++ i ] );
                        }
                }
        }
 }
 
-#ifdef __DARWIN__
+#if (defined(__DARWIN__) || defined(WIN32)) && !defined(MELT_NOSDL)
 
 static void event_handling( mlt_producer producer, mlt_consumer consumer )
 {
@@ -263,7 +385,7 @@ static void transport( mlt_producer producer, mlt_consumer consumer )
                                transport_action( producer, string );
                        }
 
-#ifdef __DARWIN__
+#if (defined(__DARWIN__) || defined(WIN32)) && !defined(MELT_NOSDL)
                        event_handling( producer, consumer );
 #endif
 
@@ -274,14 +396,15 @@ static void transport( mlt_producer producer, mlt_consumer consumer )
                                        int current_position = mlt_producer_position( producer );
                                        if ( current_position > last_position )
                                        {
-                                               fprintf( stderr, "Current Frame: %10d, percentage: %10d\r",
-                                                       current_position, 100 * current_position / total_length );
+                                               fprintf( stderr, "Current Frame: %10d, percentage: %10d%c",
+                                                       current_position, 100 * current_position / total_length,
+                                                       progress == 2 ? '\n' : '\r' );
                                                last_position = current_position;
                                        }
                                }
                                else
                                {
-                                       fprintf( stderr, "Current Position: %10d\r", (int)mlt_producer_position( producer ) );
+                                       fprintf( stderr, "Current Position: %10d\r", (int)mlt_consumer_position( consumer ) );
                                }
                        }
 
@@ -294,39 +417,52 @@ static void transport( mlt_producer producer, mlt_consumer consumer )
        }
 }
 
-static void guess_profile( mlt_producer melt, mlt_profile profile )
+static void show_usage( char *program_name )
 {
-       mlt_frame fr = NULL;
-       uint8_t *buffer;
-       mlt_image_format fmt = mlt_image_yuv422;
-       mlt_properties p;
-       int w = profile->width;
-       int h = profile->height;
-
-       if ( ! mlt_service_get_frame( MLT_PRODUCER_SERVICE(melt), &fr, 0 ) && fr )
-       {
-               if ( ! mlt_frame_get_image( fr, &buffer, &fmt, &w, &h, 0 ) )
-               {
-                       // Some source properties are not exposed until after the first get_image call.
-                       mlt_frame_close( fr );
-                       mlt_service_get_frame( MLT_PRODUCER_SERVICE(melt), &fr, 0 );
-                       p = MLT_FRAME_PROPERTIES( fr );
-                       if ( mlt_properties_get_int( p, "meta.media.width" ) )
-                       {
-                               profile->width = mlt_properties_get_int( p, "meta.media.width" );
-                               profile->height = mlt_properties_get_int( p, "meta.media.height" );
-                               profile->progressive = mlt_properties_get_int( p, "meta.media.progressive" );
-                               profile->frame_rate_num = mlt_properties_get_int( p, "meta.media.frame_rate_num" );
-                               profile->frame_rate_den = mlt_properties_get_int( p, "meta.media.frame_rate_den" );
-                               profile->sample_aspect_num = mlt_properties_get_int( p, "meta.media.sample_aspect_num" );
-                               profile->sample_aspect_den = mlt_properties_get_int( p, "meta.media.sample_aspect_den" );
-                               profile->display_aspect_num = (int) ( (double) profile->sample_aspect_num * profile->width / profile->sample_aspect_den + 0.5 );
-                               profile->display_aspect_den = profile->height;
-                       }
-               }
-       }
-       mlt_frame_close( fr );
-       mlt_producer_seek( melt, 0 );
+       fprintf( stdout,
+"Usage: %s [options] [producer [name=value]* ]+\n"
+"Options:\n"
+"  -attach filter[:arg] [name=value]*       Attach a filter to the output\n"
+"  -attach-cut filter[:arg] [name=value]*   Attach a filter to a cut\n"
+"  -attach-track filter[:arg] [name=value]* Attach a filter to a track\n"
+"  -attach-clip filter[:arg] [name=value]*  Attach a filter to a producer\n"
+"  -audio-track | -hide-video               Add an audio-only track\n"
+"  -blank frames                            Add blank silence to a track\n"
+"  -consumer id[:arg] [name=value]*         Set the consumer (sink)\n"
+"  -debug                                   Set the logging level to debug\n"
+"  -filter filter[:arg] [name=value]*       Add a filter to the current track\n"
+"  -group [name=value]*                     Apply properties repeatedly\n"
+"  -help                                    Show this message\n"
+"  -jack                                    Enable JACK transport synchronization\n"
+"  -join clips                              Join multiple clips into one cut\n"
+"  -mix length                              Add a mix between the last two cuts\n"
+"  -mixer transition                        Add a transition to the mix\n"
+"  -null-track | -hide-track                Add a hidden track\n"
+"  -profile name                            Set the processing settings\n"
+"  -progress                                Display progress along with position\n"
+"  -remove                                  Remove the most recent cut\n"
+"  -repeat times                            Repeat the last cut\n"
+"  -query                                   List all of the registered services\n"
+"  -query \"consumers\" | \"consumer\"=id       List consumers or show info about one\n"
+"  -query \"filters\" | \"filter\"=id           List filters or show info about one\n"
+"  -query \"producers\" | \"producer\"=id       List producers or show info about one\n"
+"  -query \"transitions\" | \"transition\"=id   List transitions, show info about one\n"
+"  -query \"profiles\" | \"profile\"=id         List profiles, show info about one\n"
+"  -query \"presets\" | \"preset\"=id           List presets, show info about one\n"
+"  -query \"formats\"                         List audio/video formats\n"
+"  -query \"audio_codecs\"                    List audio codecs\n"
+"  -query \"video_codecs\"                    List video codecs\n"
+"  -serialise [filename]                    Write the commands to a text file\n"
+"  -silent                                  Do not display position/transport\n"
+"  -split relative-frame                    Split the last cut into two cuts\n"
+"  -swap                                    Rearrange the last two cuts\n"
+"  -track                                   Add a track\n"
+"  -transition id[:arg] [name=value]*       Add a transition\n"
+"  -verbose                                 Set the logging level to verbose\n"
+"  -version                                 Show the version and copyright\n"
+"  -video-track | -hide-audio               Add a video-only track\n"
+"For more help: <http://www.mltframework.org/>\n",
+       basename( program_name ) );
 }
 
 static void query_metadata( mlt_repository repo, mlt_service_type type, const char *typestr, char *id )
@@ -335,15 +471,40 @@ static void query_metadata( mlt_repository repo, mlt_service_type type, const ch
        if ( metadata )
        {
                char *s = mlt_properties_serialise_yaml( metadata );
-               fprintf( stderr, "%s", s );
+               fprintf( stdout, "%s", s );
                free( s );
        }
        else
        {
-               fprintf( stderr, "# No metadata for %s \"%s\"\n", typestr, id );
+               fprintf( stdout, "# No metadata for %s \"%s\"\n", typestr, id );
        }
 }
 
+static int is_service_hidden(mlt_repository repo, mlt_service_type type, const char *service_name )
+{
+       mlt_properties metadata = NULL;
+       mlt_properties tags = NULL;
+       metadata = mlt_repository_metadata(repo, type, service_name);
+
+       if( metadata )
+       {
+               tags = mlt_properties_get_data( metadata, "tags", NULL );
+               if( tags )
+               {
+                       int k;
+                       for ( k = 0; k < mlt_properties_count( tags ); k++ )
+                       {
+                               const char* value = mlt_properties_get_value(tags, k);
+                               if( !strcmp("Hidden", value) )
+                               {
+                                       return 1;
+                               }
+                       }
+               }
+       }
+       return 0;
+}
+
 static void query_services( mlt_repository repo, mlt_service_type type )
 {
        mlt_properties services = NULL;
@@ -369,14 +530,131 @@ static void query_services( mlt_repository repo, mlt_service_type type )
                default:
                        return;
        }
-       fprintf( stderr, "---\n%s:\n", typestr );
+       fprintf( stdout, "---\n%s:\n", typestr );
        if ( services )
        {
                int j;
                for ( j = 0; j < mlt_properties_count( services ); j++ )
-                       fprintf( stderr, "  - %s\n", mlt_properties_get_name( services, j ) );
+               {
+                       const char* service_name = mlt_properties_get_name( services, j );
+                       if( !is_service_hidden(repo, type, service_name ) )
+                               fprintf( stdout, "  - %s\n", service_name );
+               }
+       }
+       fprintf( stdout, "...\n" );
+}
+
+static void query_profiles()
+{
+       mlt_properties profiles = mlt_profile_list();
+       fprintf( stdout, "---\nprofiles:\n" );
+       if ( profiles )
+       {
+               int j;
+               for ( j = 0; j < mlt_properties_count( profiles ); j++ )
+                       fprintf( stdout, "  - %s\n", mlt_properties_get_name( profiles, j ) );
+       }
+       fprintf( stdout, "...\n" );
+       mlt_properties_close( profiles );
+}
+
+static void query_profile( const char *id )
+{
+       mlt_properties profiles = mlt_profile_list();
+       mlt_properties profile = mlt_properties_get_data( profiles, id, NULL );
+       if ( profile )
+       {
+               char *s = mlt_properties_serialise_yaml( profile );
+               fprintf( stdout, "%s", s );
+               free( s );
+       }
+       else
+       {
+               fprintf( stdout, "# No metadata for profile \"%s\"\n", id );
+       }
+       mlt_properties_close( profiles );
+}
+
+static void query_presets()
+{
+       mlt_properties presets = mlt_repository_presets();
+       fprintf( stdout, "---\npresets:\n" );
+       if ( presets )
+       {
+               int j;
+               for ( j = 0; j < mlt_properties_count( presets ); j++ )
+                       fprintf( stdout, "  - %s\n", mlt_properties_get_name( presets, j ) );
+       }
+       fprintf( stdout, "...\n" );
+       mlt_properties_close( presets );
+}
+
+static void query_preset( const char *id )
+{
+       mlt_properties presets = mlt_repository_presets();
+       mlt_properties preset = mlt_properties_get_data( presets, id, NULL );
+       if ( preset )
+       {
+               char *s = mlt_properties_serialise_yaml( preset );
+               fprintf( stdout, "%s", s );
+               free( s );
+       }
+       else
+       {
+               fprintf( stdout, "# No metadata for preset \"%s\"\n", id );
+       }
+       mlt_properties_close( presets );
+}
+
+static void query_formats( )
+{
+       mlt_consumer consumer = mlt_factory_consumer( NULL, "avformat", NULL );
+       if ( consumer )
+       {
+               mlt_properties_set( MLT_CONSUMER_PROPERTIES(consumer), "f", "list" );
+               mlt_consumer_start( consumer );
+               mlt_consumer_close( consumer );
+       }
+       else
+       {
+               fprintf( stdout, "# No formats - failed to load avformat consumer\n" );
+       }
+}
+
+static void query_acodecs( )
+{
+       mlt_consumer consumer = mlt_factory_consumer( NULL, "avformat", NULL );
+       if ( consumer )
+       {
+               mlt_properties_set( MLT_CONSUMER_PROPERTIES(consumer), "acodec", "list" );
+               mlt_consumer_start( consumer );
+               mlt_consumer_close( consumer );
+       }
+       else
+       {
+               fprintf( stdout, "# No audio codecs - failed to load avformat consumer\n" );
        }
-       fprintf( stderr, "...\n" );
+}
+
+static void query_vcodecs( )
+{
+       mlt_consumer consumer = mlt_factory_consumer( NULL, "avformat", NULL );
+       if ( consumer )
+       {
+               mlt_properties_set( MLT_CONSUMER_PROPERTIES(consumer), "vcodec", "list" );
+               mlt_consumer_start( consumer );
+               mlt_consumer_close( consumer );
+       }
+       else
+       {
+               fprintf( stdout, "# No video codecs - failed to load avformat consumer\n" );
+       }
+}
+
+static void on_fatal_error( mlt_properties owner, mlt_consumer consumer )
+{
+       mlt_consumer_stop( consumer );
+       exit( EXIT_FAILURE );
 }
 
 int main( int argc, char **argv )
@@ -387,14 +665,17 @@ int main( int argc, char **argv )
        FILE *store = NULL;
        char *name = NULL;
        mlt_profile profile = NULL;
-       mlt_profile backup_profile = NULL;
        int is_progress = 0;
        int is_silent = 0;
-       int is_profile_explicit = 0;
+       mlt_profile backup_profile;
 
        // Construct the factory
        mlt_repository repo = mlt_factory_init( NULL );
 
+#ifdef WIN32
+       is_silent = 1;
+#endif
+       
        for ( i = 1; i < argc; i ++ )
        {
                // Check for serialisation switch
@@ -421,6 +702,10 @@ int main( int argc, char **argv )
                {
                        is_progress = 1;
                }
+               else if ( !strcmp( argv[ i ], "-progress2" ) )
+               {
+                       is_progress = 2;
+               }
                // Look for the query option
                else if ( !strcmp( argv[ i ], "-query" ) )
                {
@@ -435,7 +720,17 @@ int main( int argc, char **argv )
                                        query_services( repo, producer_type );
                                else if ( !strcmp( pname, "transitions" ) || !strcmp( pname, "transition" ) )
                                        query_services( repo, transition_type );
-                               
+                               else if ( !strcmp( pname, "profiles" ) || !strcmp( pname, "profile" ) )
+                                       query_profiles();
+                               else if ( !strcmp( pname, "presets" ) || !strcmp( pname, "preset" ) )
+                                       query_presets();
+                               else if ( !strncmp( pname, "format", 6 ) )
+                                       query_formats();
+                               else if ( !strncmp( pname, "acodec", 6 ) || !strcmp( pname, "audio_codecs" ) )
+                                       query_acodecs();
+                               else if ( !strncmp( pname, "vcodec", 6 ) || !strcmp( pname, "video_codecs" ) )
+                                       query_vcodecs();
+
                                else if ( !strncmp( pname, "consumer=", 9 ) )
                                        query_metadata( repo, consumer_type, "consumer", strchr( pname, '=' ) + 1 );
                                else if ( !strncmp( pname, "filter=", 7 ) )
@@ -444,6 +739,10 @@ int main( int argc, char **argv )
                                        query_metadata( repo, producer_type, "producer", strchr( pname, '=' ) + 1 );
                                else if ( !strncmp( pname, "transition=", 11 ) )
                                        query_metadata( repo, transition_type, "transition", strchr( pname, '=' ) + 1 );
+                               else if ( !strncmp( pname, "profile=", 8 ) )
+                                       query_profile( strchr( pname, '=' ) + 1 );
+                               else if ( !strncmp( pname, "preset=", 7 ) )
+                                       query_preset( strchr( pname, '=' ) + 1 );
                                else
                                        goto query_all;
                        }
@@ -454,7 +753,7 @@ query_all:
                                query_services( repo, filter_type );
                                query_services( repo, producer_type );
                                query_services( repo, transition_type );
-                               fprintf( stderr, "# You can query the metadata for a specific service using:\n"
+                               fprintf( stdout, "# You can query the metadata for a specific service using:\n"
                                        "# -query <type>=<identifer>\n"
                                        "# where <type> is one of: consumer, filter, producer, or transition.\n" );
                        }
@@ -470,8 +769,8 @@ query_all:
                }
                else if ( !strcmp( argv[ i ], "-version" ) || !strcmp( argv[ i ], "--version" ) )
                {
-                       fprintf( stderr, "MLT %s " VERSION "\n"
-                               "Copyright (C) 2002-2010 Ushodaya Enterprises Limited\n"
+                       fprintf( stdout, "%s " VERSION "\n"
+                               "Copyright (C) 2002-2012 Ushodaya Enterprises Limited\n"
                                "<http://www.mltframework.org/>\n"
                                "This is free software; see the source for copying conditions.  There is NO\n"
                                "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
@@ -483,20 +782,32 @@ query_all:
                        mlt_log_set_level( MLT_LOG_DEBUG );
                }
        }
+       if ( !is_silent && !isatty( STDIN_FILENO ) )
+               is_progress = 1;
 
        // Create profile if not set explicitly
+       if ( getenv( "MLT_PROFILE" ) )
+               profile = mlt_profile_init( NULL );
        if ( profile == NULL )
                profile = mlt_profile_init( NULL );
        else
-               is_profile_explicit = 1;
+               profile->is_explicit = 1;
 
        // Look for the consumer option to load profile settings from consumer properties
-       load_consumer( &consumer, argc, argv );
-
-       // Make backup of profile for determining if we need to use 'consumer' producer.
-       backup_profile = mlt_profile_init( NULL );
-       memcpy( backup_profile, profile, sizeof( struct mlt_profile_s ) );
-       backup_profile->description = strdup( "" );
+       backup_profile = mlt_profile_clone( profile );
+       load_consumer( &consumer, profile, argc, argv );
+
+       // If the consumer changed the profile, then it is explicit.
+       if ( backup_profile && !profile->is_explicit && (
+            profile->width != backup_profile->width ||
+            profile->height != backup_profile->height ||
+            profile->sample_aspect_num != backup_profile->sample_aspect_num ||
+            profile->sample_aspect_den != backup_profile->sample_aspect_den ||
+            profile->frame_rate_den != backup_profile->frame_rate_den ||
+            profile->frame_rate_num != backup_profile->frame_rate_num ||
+            profile->colorspace != backup_profile->colorspace ) )
+               profile->is_explicit = 1;
+       mlt_profile_close( backup_profile );
 
        // Get melt producer
        if ( argc > 1 )
@@ -504,34 +815,30 @@ query_all:
 
        if ( melt )
        {
-               // If the producer changed the profile then do not try to guess it.
-               if ( profile->width != backup_profile->width ||
-                    profile->height != backup_profile->height ||
-                    profile->sample_aspect_num != backup_profile->sample_aspect_num ||
-                    profile->sample_aspect_den != backup_profile->sample_aspect_den )
+               // Generate an automatic profile if needed.
+               if ( ! profile->is_explicit )
                {
-                       if ( is_profile_explicit )
-                       {
-                               // We need to use the 'consumer' producer.
-                               mlt_producer_close( melt );
-                               mlt_profile_close( profile );
-                               profile = backup_profile;
-                               backup_profile = NULL;
-                               if ( profile->description )
-                                       free( profile->description );
-                               // This is a hack to signal create_producer() in producer_melt.c.
-                               profile->description = strdup( "consumer:" );
-                               melt = mlt_factory_producer( profile, "melt", &argv[ 1 ] );
-                       }
+                       mlt_profile_from_producer( profile, melt );
+                       mlt_producer_close( melt );
+                       melt = mlt_factory_producer( profile, "melt", &argv[ 1 ] );
                }
-               else if ( ! is_profile_explicit )
+               
+               // Reload the consumer with the fully qualified profile.
+               // The producer or auto-profile could have changed the profile.
+               load_consumer( &consumer, profile, argc, argv );
+
+               // See if producer has consumer already attached
+               if ( !store && !consumer )
                {
-                       guess_profile( melt, profile );
+                       consumer = MLT_CONSUMER( mlt_service_consumer( MLT_PRODUCER_SERVICE( melt ) ) );
+                       if ( consumer )
+                       {
+                               mlt_properties_inc_ref( MLT_CONSUMER_PROPERTIES(consumer) ); // because we explicitly close it
+                               mlt_properties_set_data( MLT_CONSUMER_PROPERTIES(consumer),
+                                       "transport_callback", transport_action, 0, NULL, NULL );
+                       }
                }
 
-               // Reload the consumer with the fully qualified profile
-               load_consumer( consumer, argc, argv );
-
                // If we have no consumer, default to sdl
                if ( store == NULL && consumer == NULL )
                        consumer = create_consumer( profile, NULL );
@@ -553,7 +860,11 @@ query_all:
                // Parse the arguments
                for ( i = 1; i < argc; i ++ )
                {
-                       if ( !strcmp( argv[ i ], "-serialise" ) )
+                       if ( !strcmp( argv[ i ], "-jack" ) )
+                       {
+                               setup_jack_transport( consumer, profile );
+                       }
+                       else if ( !strcmp( argv[ i ], "-serialise" ) )
                        {
                                if ( store != stdout )
                                        i ++;
@@ -592,13 +903,15 @@ query_all:
                        mlt_consumer_connect( consumer, MLT_PRODUCER_SERVICE( melt ) );
 
                        // Start the consumer
-                       mlt_consumer_start( consumer );
-
-                       // Transport functionality
-                       transport( melt, consumer );
-
-                       // Stop the consumer
-                       mlt_consumer_stop( consumer );
+                       mlt_events_listen( properties, consumer, "consumer-fatal-error", ( mlt_listener )on_fatal_error );
+                       if ( mlt_consumer_start( consumer ) == 0 )
+                       {
+                               // Transport functionality
+                               transport( melt, consumer );
+                               
+                               // Stop the consumer
+                               mlt_consumer_stop( consumer );
+                       }       
                }
                else if ( store != NULL && store != stdout && name != NULL )
                {
@@ -608,46 +921,13 @@ query_all:
        }
        else
        {
-               fprintf( stderr,
-"Usage: %s [options] [producer [name=value]* ]+\n"
-"Options:\n"
-"  -attach filter[:arg] [name=value]*       Attach a filter to the output\n"
-"  -attach-cut filter[:arg] [name=value]*   Attach a filter to a cut\n"
-"  -attach-track filter[:arg] [name=value]* Attach a filter to a track\n"
-"  -attach-clip filter[:arg] [name=value]*  Attach a filter to a producer\n"
-"  -audio-track | -hide-video               Add an audio-only track\n"
-"  -blank frames                            Add blank silence to a track\n"
-"  -consumer id[:arg] [name=value]*         Set the consumer (sink)\n"
-"  -debug                                   Set the logging level to debug\n"
-"  -filter filter[:arg] [name=value]*       Add a filter to the current track\n"
-"  -group [name=value]*                     Apply properties repeatedly\n"
-"  -help                                    Show this message\n"
-"  -join clips                              Join multiple clips into one cut\n"
-"  -mix length                              Add a mix between the last two cuts\n"
-"  -mixer transition                        Add a transition to the mix\n"
-"  -null-track | -hide-track                Add a hidden track\n"
-"  -profile name                            Set the processing settings\n"
-"  -progress                                Display progress along with position\n"
-"  -remove                                  Remove the most recent cut\n"
-"  -repeat times                            Repeat the last cut\n"
-"  -query                                   List all of the registered services\n"
-"  -query \"consumers\" | \"consumer\"=id       List consumers or show info about one\n"
-"  -query \"filters\" | \"filter\"=id           List filters or show info about one\n"
-"  -query \"producers\" | \"producer\"=id       List producers or show info about one\n"
-"  -query \"transitions\" | \"transition\"=id   List transitions, show info about one\n"
-"  -serialise [filename]                    Write the commands to a text file\n"
-"  -silent                                  Do not display position/transport\n"
-"  -split relative-frame                    Split the last cut into two cuts\n"
-"  -swap                                    Rearrange the last two cuts\n"
-"  -track                                   Add a track\n"
-"  -transition id[:arg] [name=value]*       Add a transition\n"
-"  -verbose                                 Set the logging level to verbose\n"
-"  -version                                 Show the version and copyright\n"
-"  -video-track | -hide-audio               Add a video-only track\n"
-"For more help: <http://www.mltframework.org/>\n",
-               basename( argv[0] ) );
+               show_usage( argv[0] );
        }
 
+       // Disconnect producer from consumer to prevent ref cycles from closing services
+       if ( consumer )
+               mlt_consumer_connect( consumer, NULL );
+
        // Close the producer
        if ( melt != NULL )
                mlt_producer_close( melt );
@@ -658,7 +938,6 @@ query_all:
 
        // Close the factory
        mlt_profile_close( profile );
-       mlt_profile_close( backup_profile );
 
 exit_factory: