]> git.sesse.net Git - mlt/blobdiff - src/melt/melt.c
Add -query formats and codecs to melt.
[mlt] / src / melt / melt.c
index e98db46f1ae8796a68cfa358b87c3c1c1c1cd0cf..91e66c5c8d443e6a9a0989fffb4a31c22b02d263 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * melt.c -- MLT command line utility
- * Copyright (C) 2002-2010 Ushodaya Enterprises Limited
+ * Copyright (C) 2002-2011 Ushodaya Enterprises Limited
  * Authors: Charles Yates <charles.yates@pandora.be>
  *          Dan Dennedy <dan@dennedy.org>
  *
@@ -31,7 +31,7 @@
 
 #include <framework/mlt.h>
 
-#ifdef __DARWIN__
+#if defined(__DARWIN__) || defined(WIN32)
 #include <SDL.h>
 #endif
 
@@ -199,7 +199,7 @@ static void load_consumer( mlt_consumer *consumer, mlt_profile profile, int argc
        }
 }
 
-#ifdef __DARWIN__
+#if defined(__DARWIN__) || defined(WIN32)
 
 static void event_handling( mlt_producer producer, mlt_consumer consumer )
 {
@@ -263,7 +263,7 @@ static void transport( mlt_producer producer, mlt_consumer consumer )
                                transport_action( producer, string );
                        }
 
-#ifdef __DARWIN__
+#if defined(__DARWIN__) || defined(WIN32)
                        event_handling( producer, consumer );
 #endif
 
@@ -281,7 +281,7 @@ static void transport( mlt_producer producer, mlt_consumer consumer )
                                }
                                else
                                {
-                                       fprintf( stderr, "Current Position: %10d\r", (int)mlt_producer_position( producer ) );
+                                       fprintf( stderr, "Current Position: %10d\r", (int)mlt_consumer_position( consumer ) );
                                }
                        }
 
@@ -323,6 +323,10 @@ static void show_usage( char *program_name )
 "  -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 \"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"
@@ -347,6 +351,7 @@ static void guess_profile( mlt_producer melt, mlt_profile profile )
 
        if ( ! mlt_service_get_frame( MLT_PRODUCER_SERVICE(melt), &fr, 0 ) && fr )
        {
+               mlt_properties_set_double( MLT_FRAME_PROPERTIES( fr ), "consumer_aspect_ratio", mlt_profile_sar( profile ) );
                if ( ! mlt_frame_get_image( fr, &buffer, &fmt, &w, &h, 0 ) )
                {
                        // Some source properties are not exposed until after the first get_image call.
@@ -361,6 +366,11 @@ static void guess_profile( mlt_producer melt, mlt_profile profile )
                                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" );
+                               // AVCHD is mis-reported as double frame rate.
+                               if ( profile->progressive == 0 && (
+                                    profile->frame_rate_num / profile->frame_rate_den == 50 ||
+                                    profile->frame_rate_num / profile->frame_rate_den == 59 ) )
+                                       profile->frame_rate_num /= 2;
                                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->colorspace = mlt_properties_get_int( p, "meta.media.colorspace" );
@@ -426,6 +436,88 @@ static void query_services( mlt_repository repo, mlt_service_type type )
        fprintf( stderr, "...\n" );
 }
 
+static void query_profiles()
+{
+       mlt_properties profiles = mlt_profile_list();
+       fprintf( stderr, "---\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( stderr, "...\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( stderr, "%s", s );
+               free( s );
+       }
+       else
+       {
+               fprintf( stderr, "# No metadata for profile \"%s\"\n", id );
+       }
+       mlt_properties_close( profiles );
+}
+
+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( stderr, "# 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( stderr, "# No audio codecs - failed to load avformat consumer\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( stderr, "# 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 )
 {
        int i;
@@ -441,6 +533,10 @@ int main( int argc, char **argv )
        // 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
@@ -481,7 +577,15 @@ 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 ( !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 ) )
@@ -490,6 +594,8 @@ 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
                                        goto query_all;
                        }
@@ -517,7 +623,7 @@ 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"
+                               "Copyright (C) 2002-2011 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",
@@ -531,6 +637,8 @@ query_all:
        }
 
        // Create profile if not set explicitly
+       if ( getenv( "MLT_PROFILE" ) )
+               profile = mlt_profile_init( NULL );
        if ( profile == NULL )
                profile = mlt_profile_init( NULL );
        else
@@ -630,13 +738,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 )
                {