/*
* 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>
*
#include <framework/mlt.h>
-#ifdef __DARWIN__
+#if defined(__DARWIN__) || defined(WIN32)
#include <SDL.h>
#endif
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 );
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 );
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 );
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;
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;
}
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;
}
}
-#ifdef __DARWIN__
+#if defined(__DARWIN__) || defined(WIN32)
static void event_handling( mlt_producer producer, mlt_consumer consumer )
{
transport_action( producer, string );
}
-#ifdef __DARWIN__
+#if defined(__DARWIN__) || defined(WIN32)
event_handling( producer, consumer );
#endif
" -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"
" -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"
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_presets()
+{
+ mlt_properties presets = mlt_repository_presets();
+ fprintf( stderr, "---\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( stderr, "...\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( stderr, "%s", s );
+ free( s );
+ }
+ else
+ {
+ fprintf( stderr, "# 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( 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 );
// 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
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 ) )
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;
}
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",
}
// Create profile if not set explicitly
+ if ( getenv( "MLT_PROFILE" ) )
+ profile = mlt_profile_init( NULL );
if ( profile == NULL )
profile = mlt_profile_init( NULL );
else
// 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 ++;