]> 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 14b1e7f7c40700a48599abf8f44747008c25d100..c125a72e511364594856cb46e652b90551bc456d 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * melt.c -- MLT command line utility
- * Copyright (C) 2002-2011 Ushodaya Enterprises Limited
+ * Copyright (C) 2002-2012 Ushodaya Enterprises Limited
  * Authors: Charles Yates <charles.yates@pandora.be>
  *          Dan Dennedy <dan@dennedy.org>
  *
@@ -32,7 +32,7 @@
 
 #include <framework/mlt.h>
 
-#if defined(__DARWIN__) || defined(WIN32)
+#if (defined(__DARWIN__) || defined(WIN32)) && !defined(MELT_NOSDL)
 #include <SDL.h>
 #endif
 
@@ -262,7 +262,49 @@ static mlt_consumer create_consumer( mlt_profile profile, char *id )
 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" ) )
                {
@@ -272,14 +314,14 @@ static void load_consumer( mlt_consumer *consumer, mlt_profile profile, int argc
                        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 ] );
                        }
                }
        }
 }
 
-#if defined(__DARWIN__) || defined(WIN32)
+#if (defined(__DARWIN__) || defined(WIN32)) && !defined(MELT_NOSDL)
 
 static void event_handling( mlt_producer producer, mlt_consumer consumer )
 {
@@ -343,7 +385,7 @@ static void transport( mlt_producer producer, mlt_consumer consumer )
                                transport_action( producer, string );
                        }
 
-#if defined(__DARWIN__) || defined(WIN32)
+#if (defined(__DARWIN__) || defined(WIN32)) && !defined(MELT_NOSDL)
                        event_handling( producer, consumer );
 #endif
 
@@ -354,8 +396,9 @@ 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;
                                        }
                                }
@@ -376,7 +419,7 @@ static void transport( mlt_producer producer, mlt_consumer consumer )
 
 static void show_usage( char *program_name )
 {
-       fprintf( stderr,
+       fprintf( stdout,
 "Usage: %s [options] [producer [name=value]* ]+\n"
 "Options:\n"
 "  -attach filter[:arg] [name=value]*       Attach a filter to the output\n"
@@ -428,13 +471,38 @@ 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 )
@@ -462,27 +530,31 @@ 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( stderr, "...\n" );
+       fprintf( stdout, "...\n" );
 }
 
 static void query_profiles()
 {
        mlt_properties profiles = mlt_profile_list();
-       fprintf( stderr, "---\nprofiles:\n" );
+       fprintf( stdout, "---\nprofiles:\n" );
        if ( profiles )
        {
                int j;
                for ( j = 0; j < mlt_properties_count( profiles ); j++ )
-                       fprintf( stderr, "  - %s\n", mlt_properties_get_name( profiles, j ) );
+                       fprintf( stdout, "  - %s\n", mlt_properties_get_name( profiles, j ) );
        }
-       fprintf( stderr, "...\n" );
+       fprintf( stdout, "...\n" );
        mlt_properties_close( profiles );
 }
 
@@ -493,12 +565,12 @@ static void query_profile( const char *id )
        if ( profile )
        {
                char *s = mlt_properties_serialise_yaml( profile );
-               fprintf( stderr, "%s", s );
+               fprintf( stdout, "%s", s );
                free( s );
        }
        else
        {
-               fprintf( stderr, "# No metadata for profile \"%s\"\n", id );
+               fprintf( stdout, "# No metadata for profile \"%s\"\n", id );
        }
        mlt_properties_close( profiles );
 }
@@ -506,14 +578,14 @@ static void query_profile( const char *id )
 static void query_presets()
 {
        mlt_properties presets = mlt_repository_presets();
-       fprintf( stderr, "---\npresets:\n" );
+       fprintf( stdout, "---\npresets:\n" );
        if ( presets )
        {
                int j;
                for ( j = 0; j < mlt_properties_count( presets ); j++ )
-                       fprintf( stderr, "  - %s\n", mlt_properties_get_name( presets, j ) );
+                       fprintf( stdout, "  - %s\n", mlt_properties_get_name( presets, j ) );
        }
-       fprintf( stderr, "...\n" );
+       fprintf( stdout, "...\n" );
        mlt_properties_close( presets );
 }
 
@@ -524,12 +596,12 @@ static void query_preset( const char *id )
        if ( preset )
        {
                char *s = mlt_properties_serialise_yaml( preset );
-               fprintf( stderr, "%s", s );
+               fprintf( stdout, "%s", s );
                free( s );
        }
        else
        {
-               fprintf( stderr, "# No metadata for preset \"%s\"\n", id );
+               fprintf( stdout, "# No metadata for preset \"%s\"\n", id );
        }
        mlt_properties_close( presets );
 }
@@ -545,7 +617,7 @@ static void query_formats( )
        }
        else
        {
-               fprintf( stderr, "# No formats - failed to load avformat consumer\n" );
+               fprintf( stdout, "# No formats - failed to load avformat consumer\n" );
        }
 }
 
@@ -560,7 +632,7 @@ static void query_acodecs( )
        }
        else
        {
-               fprintf( stderr, "# No audio codecs - failed to load avformat consumer\n" );
+               fprintf( stdout, "# No audio codecs - failed to load avformat consumer\n" );
        }
 }
 
@@ -575,7 +647,7 @@ static void query_vcodecs( )
        }
        else
        {
-               fprintf( stderr, "# No video codecs - failed to load avformat consumer\n" );
+               fprintf( stdout, "# No video codecs - failed to load avformat consumer\n" );
        }
 }
 
@@ -626,10 +698,14 @@ int main( int argc, char **argv )
                        if ( pname && pname[0] != '-' )
                                profile = mlt_profile_init( pname );
                }
-               else if ( !strcmp( argv[ i ], "-progress" ) || !isatty( STDIN_FILENO ) )
+               else if ( !strcmp( argv[ i ], "-progress" ) )
                {
                        is_progress = 1;
                }
+               else if ( !strcmp( argv[ i ], "-progress2" ) )
+               {
+                       is_progress = 2;
+               }
                // Look for the query option
                else if ( !strcmp( argv[ i ], "-query" ) )
                {
@@ -677,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" );
                        }
@@ -693,8 +769,8 @@ query_all:
                }
                else if ( !strcmp( argv[ i ], "-version" ) || !strcmp( argv[ i ], "--version" ) )
                {
-                       fprintf( stderr, "MLT %s " VERSION "\n"
-                               "Copyright (C) 2002-2011 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",
@@ -706,6 +782,8 @@ 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" ) )
@@ -749,6 +827,18 @@ query_all:
                // 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 )
+               {
+                       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 );
+                       }
+               }
+
                // If we have no consumer, default to sdl
                if ( store == NULL && consumer == NULL )
                        consumer = create_consumer( profile, NULL );
@@ -834,6 +924,10 @@ query_all:
                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 );