2 * melt.c -- MLT command line utility
3 * Copyright (C) 2002-2011 Ushodaya Enterprises Limited
4 * Authors: Charles Yates <charles.yates@pandora.be>
5 * Dan Dennedy <dan@dennedy.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #include <framework/mlt.h>
34 #if defined(__DARWIN__) || defined(WIN32)
40 static void transport_action( mlt_producer producer, char *value )
42 mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
43 mlt_multitrack multitrack = mlt_properties_get_data( properties, "multitrack", NULL );
44 mlt_consumer consumer = mlt_properties_get_data( properties, "transport_consumer", NULL );
45 mlt_properties jack = mlt_properties_get_data( MLT_CONSUMER_PROPERTIES( consumer ), "jack_filter", NULL );
46 mlt_position position = mlt_producer_position( producer );
48 mlt_properties_set_int( properties, "stats_off", 1 );
50 if ( strlen( value ) == 1 )
56 mlt_properties_set_int( properties, "done", 1 );
57 mlt_events_fire( jack, "jack-stop", NULL );
61 mlt_producer_set_speed( producer, 1 );
62 mlt_producer_seek( producer, position );
63 mlt_consumer_purge( consumer );
64 mlt_events_fire( jack, "jack-seek", &position, NULL );
67 mlt_producer_set_speed( producer, -10 );
70 mlt_producer_set_speed( producer, -5 );
73 mlt_producer_set_speed( producer, -2 );
76 mlt_producer_set_speed( producer, -1 );
79 mlt_producer_set_speed( producer, 0 );
80 mlt_consumer_purge( consumer );
81 mlt_events_fire( jack, "jack-stop", NULL );
85 if ( !jack || mlt_producer_get_speed( producer ) != 0 )
86 mlt_producer_set_speed( producer, 1 );
87 mlt_consumer_purge( consumer );
88 mlt_events_fire( jack, "jack-start", NULL );
91 mlt_producer_set_speed( producer, 2 );
94 mlt_producer_set_speed( producer, 5 );
97 mlt_producer_set_speed( producer, 10 );
100 if ( multitrack != NULL )
103 mlt_position last = -1;
104 fprintf( stderr, "\n" );
105 for ( i = 0; 1; i ++ )
107 position = mlt_multitrack_clip( multitrack, mlt_whence_relative_start, i );
108 if ( position == last )
111 fprintf( stderr, "%d: %d\n", i, (int)position );
117 if ( multitrack != NULL )
119 position = mlt_multitrack_clip( multitrack, mlt_whence_relative_current, 0 );
120 mlt_producer_seek( producer, position );
121 mlt_consumer_purge( consumer );
122 mlt_events_fire( jack, "jack-seek", &position, NULL );
126 if ( producer != NULL )
128 position -= mlt_producer_get_fps( producer ) * 60;
129 mlt_consumer_purge( consumer );
130 mlt_producer_seek( producer, position );
131 mlt_events_fire( jack, "jack-seek", &position, NULL );
135 if ( producer != NULL )
138 mlt_producer_set_speed( producer, 0 );
139 mlt_consumer_purge( consumer );
140 mlt_producer_seek( producer, position );
141 mlt_events_fire( jack, "jack-stop", NULL );
142 mlt_events_fire( jack, "jack-seek", &position, NULL );
146 if ( multitrack != NULL )
148 position = mlt_multitrack_clip( multitrack, mlt_whence_relative_current, 1 );
149 mlt_consumer_purge( consumer );
150 mlt_producer_seek( producer, position );
151 mlt_events_fire( jack, "jack-seek", &position, NULL );
155 if ( multitrack != NULL )
157 position = mlt_multitrack_clip( multitrack, mlt_whence_relative_current, -1 );
158 mlt_consumer_purge( consumer );
159 mlt_producer_seek( producer, position );
160 mlt_events_fire( jack, "jack-seek", &position, NULL );
164 if ( producer != NULL )
167 mlt_consumer_purge( consumer );
168 if ( mlt_producer_get_speed( producer ) != 0 )
170 mlt_producer_set_speed( producer, 0 );
171 mlt_events_fire( jack, "jack-stop", NULL );
175 mlt_producer_seek( producer, position );
176 mlt_events_fire( jack, "jack-seek", &position, NULL );
181 if ( producer != NULL )
183 position += mlt_producer_get_fps( producer ) * 60;
184 mlt_consumer_purge( consumer );
185 mlt_producer_seek( producer, position );
186 mlt_events_fire( jack, "jack-seek", &position, NULL );
191 mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( consumer ), "refresh", 1 );
194 mlt_properties_set_int( properties, "stats_off", 0 );
197 static void on_jack_started( mlt_properties owner, mlt_consumer consumer, mlt_position *position )
199 mlt_producer producer = mlt_properties_get_data( MLT_CONSUMER_PROPERTIES(consumer), "transport_producer", NULL );
202 if ( mlt_producer_get_speed( producer ) != 0 )
204 mlt_properties jack = mlt_properties_get_data( MLT_CONSUMER_PROPERTIES( consumer ), "jack_filter", NULL );
205 mlt_events_fire( jack, "jack-stop", NULL );
209 mlt_producer_set_speed( producer, 1 );
210 mlt_consumer_purge( consumer );
211 mlt_producer_seek( producer, *position );
212 mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( consumer ), "refresh", 1 );
217 static void on_jack_stopped( mlt_properties owner, mlt_consumer consumer, mlt_position *position )
219 mlt_producer producer = mlt_properties_get_data( MLT_CONSUMER_PROPERTIES(consumer), "transport_producer", NULL );
222 mlt_producer_set_speed( producer, 0 );
223 mlt_consumer_purge( consumer );
224 mlt_producer_seek( producer, *position );
225 mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( consumer ), "refresh", 1 );
229 static void setup_jack_transport( mlt_consumer consumer, mlt_profile profile )
231 mlt_properties properties = MLT_CONSUMER_PROPERTIES( consumer );
232 mlt_filter jack = mlt_factory_filter( profile, "jackrack", NULL );
233 mlt_properties jack_properties = MLT_FILTER_PROPERTIES(jack);
235 mlt_service_attach( MLT_CONSUMER_SERVICE(consumer), jack );
236 mlt_properties_set_int( properties, "audio_off", 1 );
237 mlt_properties_set_data( properties, "jack_filter", jack, 0, (mlt_destructor) mlt_filter_close, NULL );
238 // mlt_properties_set( jack_properties, "out_1", "system:playback_1" );
239 // mlt_properties_set( jack_properties, "out_2", "system:playback_2" );
240 mlt_events_listen( jack_properties, consumer, "jack-started", (mlt_listener) on_jack_started );
241 mlt_events_listen( jack_properties, consumer, "jack-stopped", (mlt_listener) on_jack_stopped );
244 static mlt_consumer create_consumer( mlt_profile profile, char *id )
246 char *myid = id ? strdup( id ) : NULL;
247 char *arg = myid ? strchr( myid, ':' ) : NULL;
250 mlt_consumer consumer = mlt_factory_consumer( profile, myid, arg );
251 if ( consumer != NULL )
253 mlt_properties properties = MLT_CONSUMER_PROPERTIES( consumer );
254 mlt_properties_set_data( properties, "transport_callback", transport_action, 0, NULL, NULL );
261 static void load_consumer( mlt_consumer *consumer, mlt_profile profile, int argc, char **argv )
264 for ( i = 1; i < argc; i ++ )
266 if ( !strcmp( argv[ i ], "-consumer" ) )
269 mlt_consumer_close( *consumer );
270 *consumer = create_consumer( profile, argv[ ++ i ] );
273 mlt_properties properties = MLT_CONSUMER_PROPERTIES( *consumer );
274 while ( argv[ i + 1 ] != NULL && strstr( argv[ i + 1 ], "=" ) )
275 mlt_properties_parse( properties, argv[ ++ i ] );
281 #if defined(__DARWIN__) || defined(WIN32)
283 static void event_handling( mlt_producer producer, mlt_consumer consumer )
287 while ( SDL_PollEvent( &event ) )
292 mlt_properties_set_int( MLT_PRODUCER_PROPERTIES( consumer ), "done", 1 );
296 if ( event.key.keysym.unicode < 0x80 && event.key.keysym.unicode > 0 )
298 char keyboard[ 2 ] = { event.key.keysym.unicode, 0 };
299 transport_action( producer, keyboard );
308 static void transport( mlt_producer producer, mlt_consumer consumer )
310 mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
311 int silent = mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer ), "silent" );
312 int progress = mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer ), "progress" );
313 struct timespec tm = { 0, 40000 };
314 int total_length = mlt_producer_get_length( producer );
315 int last_position = 0;
317 if ( mlt_properties_get_int( properties, "done" ) == 0 && !mlt_consumer_is_stopped( consumer ) )
319 if ( !silent && !progress )
323 fprintf( stderr, "+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+\n" );
324 fprintf( stderr, "|1=-10| |2= -5| |3= -2| |4= -1| |5= 0| |6= 1| |7= 2| |8= 5| |9= 10|\n" );
325 fprintf( stderr, "+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+\n" );
327 fprintf( stderr, "+---------------------------------------------------------------------+\n" );
328 fprintf( stderr, "| H = back 1 minute, L = forward 1 minute |\n" );
329 fprintf( stderr, "| h = previous frame, l = next frame |\n" );
330 fprintf( stderr, "| g = start of clip, j = next clip, k = previous clip |\n" );
331 fprintf( stderr, "| 0 = restart, q = quit, space = play |\n" );
332 fprintf( stderr, "+---------------------------------------------------------------------+\n" );
335 while( mlt_properties_get_int( properties, "done" ) == 0 && !mlt_consumer_is_stopped( consumer ) )
337 int value = ( silent || progress )? -1 : term_read( );
341 char string[ 2 ] = { value, 0 };
342 transport_action( producer, string );
345 #if defined(__DARWIN__) || defined(WIN32)
346 event_handling( producer, consumer );
349 if ( !silent && mlt_properties_get_int( properties, "stats_off" ) == 0 )
353 int current_position = mlt_producer_position( producer );
354 if ( current_position > last_position )
356 fprintf( stderr, "Current Frame: %10d, percentage: %10d\r",
357 current_position, 100 * current_position / total_length );
358 last_position = current_position;
363 fprintf( stderr, "Current Position: %10d\r", (int)mlt_consumer_position( consumer ) );
367 if ( silent || progress )
368 nanosleep( &tm, NULL );
372 fprintf( stderr, "\n" );
376 static void show_usage( char *program_name )
379 "Usage: %s [options] [producer [name=value]* ]+\n"
381 " -attach filter[:arg] [name=value]* Attach a filter to the output\n"
382 " -attach-cut filter[:arg] [name=value]* Attach a filter to a cut\n"
383 " -attach-track filter[:arg] [name=value]* Attach a filter to a track\n"
384 " -attach-clip filter[:arg] [name=value]* Attach a filter to a producer\n"
385 " -audio-track | -hide-video Add an audio-only track\n"
386 " -blank frames Add blank silence to a track\n"
387 " -consumer id[:arg] [name=value]* Set the consumer (sink)\n"
388 " -debug Set the logging level to debug\n"
389 " -filter filter[:arg] [name=value]* Add a filter to the current track\n"
390 " -group [name=value]* Apply properties repeatedly\n"
391 " -help Show this message\n"
392 " -join clips Join multiple clips into one cut\n"
393 " -mix length Add a mix between the last two cuts\n"
394 " -mixer transition Add a transition to the mix\n"
395 " -null-track | -hide-track Add a hidden track\n"
396 " -profile name Set the processing settings\n"
397 " -progress Display progress along with position\n"
398 " -remove Remove the most recent cut\n"
399 " -repeat times Repeat the last cut\n"
400 " -query List all of the registered services\n"
401 " -query \"consumers\" | \"consumer\"=id List consumers or show info about one\n"
402 " -query \"filters\" | \"filter\"=id List filters or show info about one\n"
403 " -query \"producers\" | \"producer\"=id List producers or show info about one\n"
404 " -query \"transitions\" | \"transition\"=id List transitions, show info about one\n"
405 " -query \"profiles\" | \"profile\"=id List profiles, show info about one\n"
406 " -query \"presets\" | \"preset\"=id List presets, show info about one\n"
407 " -query \"formats\" List audio/video formats\n"
408 " -query \"audio_codecs\" List audio codecs\n"
409 " -query \"video_codecs\" List video codecs\n"
410 " -serialise [filename] Write the commands to a text file\n"
411 " -silent Do not display position/transport\n"
412 " -split relative-frame Split the last cut into two cuts\n"
413 " -swap Rearrange the last two cuts\n"
414 " -track Add a track\n"
415 " -transition id[:arg] [name=value]* Add a transition\n"
416 " -verbose Set the logging level to verbose\n"
417 " -version Show the version and copyright\n"
418 " -video-track | -hide-audio Add a video-only track\n"
419 "For more help: <http://www.mltframework.org/>\n",
420 basename( program_name ) );
423 static void guess_profile( mlt_producer melt, mlt_profile profile )
427 mlt_image_format fmt = mlt_image_yuv422;
429 int w = profile->width;
430 int h = profile->height;
432 if ( ! mlt_service_get_frame( MLT_PRODUCER_SERVICE(melt), &fr, 0 ) && fr )
434 mlt_properties_set_double( MLT_FRAME_PROPERTIES( fr ), "consumer_aspect_ratio", mlt_profile_sar( profile ) );
435 if ( ! mlt_frame_get_image( fr, &buffer, &fmt, &w, &h, 0 ) )
437 // Some source properties are not exposed until after the first get_image call.
438 mlt_frame_close( fr );
439 mlt_service_get_frame( MLT_PRODUCER_SERVICE(melt), &fr, 0 );
440 p = MLT_FRAME_PROPERTIES( fr );
441 // mlt_properties_dump(p, stderr);
442 if ( mlt_properties_get_int( p, "meta.media.frame_rate_den" ) && mlt_properties_get_int( p, "meta.media.sample_aspect_den" ) )
444 profile->width = mlt_properties_get_int( p, "meta.media.width" );
445 profile->height = mlt_properties_get_int( p, "meta.media.height" );
446 profile->progressive = mlt_properties_get_int( p, "meta.media.progressive" );
447 profile->frame_rate_num = mlt_properties_get_int( p, "meta.media.frame_rate_num" );
448 profile->frame_rate_den = mlt_properties_get_int( p, "meta.media.frame_rate_den" );
449 // AVCHD is mis-reported as double frame rate.
450 if ( profile->progressive == 0 && (
451 profile->frame_rate_num / profile->frame_rate_den == 50 ||
452 profile->frame_rate_num / profile->frame_rate_den == 59 ) )
453 profile->frame_rate_num /= 2;
454 profile->sample_aspect_num = mlt_properties_get_int( p, "meta.media.sample_aspect_num" );
455 profile->sample_aspect_den = mlt_properties_get_int( p, "meta.media.sample_aspect_den" );
456 profile->colorspace = mlt_properties_get_int( p, "meta.media.colorspace" );
457 profile->display_aspect_num = (int) ( (double) profile->sample_aspect_num * profile->width / profile->sample_aspect_den + 0.5 );
458 profile->display_aspect_den = profile->height;
459 free( profile->description );
460 profile->description = strdup( "automatic" );
461 profile->is_explicit = 0;
465 mlt_frame_close( fr );
466 mlt_producer_seek( melt, 0 );
469 static void query_metadata( mlt_repository repo, mlt_service_type type, const char *typestr, char *id )
471 mlt_properties metadata = mlt_repository_metadata( repo, type, id );
474 char *s = mlt_properties_serialise_yaml( metadata );
475 fprintf( stderr, "%s", s );
480 fprintf( stderr, "# No metadata for %s \"%s\"\n", typestr, id );
484 static void query_services( mlt_repository repo, mlt_service_type type )
486 mlt_properties services = NULL;
487 const char *typestr = NULL;
491 services = mlt_repository_consumers( repo );
492 typestr = "consumers";
495 services = mlt_repository_filters( repo );
499 services = mlt_repository_producers( repo );
500 typestr = "producers";
502 case transition_type:
503 services = mlt_repository_transitions( repo );
504 typestr = "transitions";
509 fprintf( stderr, "---\n%s:\n", typestr );
513 for ( j = 0; j < mlt_properties_count( services ); j++ )
514 fprintf( stderr, " - %s\n", mlt_properties_get_name( services, j ) );
516 fprintf( stderr, "...\n" );
519 static void query_profiles()
521 mlt_properties profiles = mlt_profile_list();
522 fprintf( stderr, "---\nprofiles:\n" );
526 for ( j = 0; j < mlt_properties_count( profiles ); j++ )
527 fprintf( stderr, " - %s\n", mlt_properties_get_name( profiles, j ) );
529 fprintf( stderr, "...\n" );
530 mlt_properties_close( profiles );
533 static void query_profile( const char *id )
535 mlt_properties profiles = mlt_profile_list();
536 mlt_properties profile = mlt_properties_get_data( profiles, id, NULL );
539 char *s = mlt_properties_serialise_yaml( profile );
540 fprintf( stderr, "%s", s );
545 fprintf( stderr, "# No metadata for profile \"%s\"\n", id );
547 mlt_properties_close( profiles );
550 static void query_presets()
552 mlt_properties presets = mlt_repository_presets();
553 fprintf( stderr, "---\npresets:\n" );
557 for ( j = 0; j < mlt_properties_count( presets ); j++ )
558 fprintf( stderr, " - %s\n", mlt_properties_get_name( presets, j ) );
560 fprintf( stderr, "...\n" );
561 mlt_properties_close( presets );
564 static void query_preset( const char *id )
566 mlt_properties presets = mlt_repository_presets();
567 mlt_properties preset = mlt_properties_get_data( presets, id, NULL );
570 char *s = mlt_properties_serialise_yaml( preset );
571 fprintf( stderr, "%s", s );
576 fprintf( stderr, "# No metadata for preset \"%s\"\n", id );
578 mlt_properties_close( presets );
581 static void query_formats( )
583 mlt_consumer consumer = mlt_factory_consumer( NULL, "avformat", NULL );
586 mlt_properties_set( MLT_CONSUMER_PROPERTIES(consumer), "f", "list" );
587 mlt_consumer_start( consumer );
588 mlt_consumer_close( consumer );
592 fprintf( stderr, "# No formats - failed to load avformat consumer\n" );
596 static void query_acodecs( )
598 mlt_consumer consumer = mlt_factory_consumer( NULL, "avformat", NULL );
601 mlt_properties_set( MLT_CONSUMER_PROPERTIES(consumer), "acodec", "list" );
602 mlt_consumer_start( consumer );
603 mlt_consumer_close( consumer );
607 fprintf( stderr, "# No audio codecs - failed to load avformat consumer\n" );
611 static void query_vcodecs( )
613 mlt_consumer consumer = mlt_factory_consumer( NULL, "avformat", NULL );
616 mlt_properties_set( MLT_CONSUMER_PROPERTIES(consumer), "vcodec", "list" );
617 mlt_consumer_start( consumer );
618 mlt_consumer_close( consumer );
622 fprintf( stderr, "# No video codecs - failed to load avformat consumer\n" );
626 static void on_fatal_error( mlt_properties owner, mlt_consumer consumer )
628 mlt_consumer_stop( consumer );
629 exit( EXIT_FAILURE );
632 int main( int argc, char **argv )
635 mlt_consumer consumer = NULL;
636 mlt_producer melt = NULL;
639 mlt_profile profile = NULL;
642 mlt_profile backup_profile;
644 // Construct the factory
645 mlt_repository repo = mlt_factory_init( NULL );
651 for ( i = 1; i < argc; i ++ )
653 // Check for serialisation switch
654 if ( !strcmp( argv[ i ], "-serialise" ) )
657 if ( name != NULL && strstr( name, ".melt" ) )
658 store = fopen( name, "w" );
661 if ( name == NULL || name[0] == '-' )
666 // Look for the profile option
667 else if ( !strcmp( argv[ i ], "-profile" ) )
669 const char *pname = argv[ ++ i ];
670 if ( pname && pname[0] != '-' )
671 profile = mlt_profile_init( pname );
673 else if ( !strcmp( argv[ i ], "-progress" ) )
677 // Look for the query option
678 else if ( !strcmp( argv[ i ], "-query" ) )
680 const char *pname = argv[ ++ i ];
681 if ( pname && pname[0] != '-' )
683 if ( !strcmp( pname, "consumers" ) || !strcmp( pname, "consumer" ) )
684 query_services( repo, consumer_type );
685 else if ( !strcmp( pname, "filters" ) || !strcmp( pname, "filter" ) )
686 query_services( repo, filter_type );
687 else if ( !strcmp( pname, "producers" ) || !strcmp( pname, "producer" ) )
688 query_services( repo, producer_type );
689 else if ( !strcmp( pname, "transitions" ) || !strcmp( pname, "transition" ) )
690 query_services( repo, transition_type );
691 else if ( !strcmp( pname, "profiles" ) || !strcmp( pname, "profile" ) )
693 else if ( !strcmp( pname, "presets" ) || !strcmp( pname, "preset" ) )
695 else if ( !strncmp( pname, "format", 6 ) )
697 else if ( !strncmp( pname, "acodec", 6 ) || !strcmp( pname, "audio_codecs" ) )
699 else if ( !strncmp( pname, "vcodec", 6 ) || !strcmp( pname, "video_codecs" ) )
702 else if ( !strncmp( pname, "consumer=", 9 ) )
703 query_metadata( repo, consumer_type, "consumer", strchr( pname, '=' ) + 1 );
704 else if ( !strncmp( pname, "filter=", 7 ) )
705 query_metadata( repo, filter_type, "filter", strchr( pname, '=' ) + 1 );
706 else if ( !strncmp( pname, "producer=", 9 ) )
707 query_metadata( repo, producer_type, "producer", strchr( pname, '=' ) + 1 );
708 else if ( !strncmp( pname, "transition=", 11 ) )
709 query_metadata( repo, transition_type, "transition", strchr( pname, '=' ) + 1 );
710 else if ( !strncmp( pname, "profile=", 8 ) )
711 query_profile( strchr( pname, '=' ) + 1 );
712 else if ( !strncmp( pname, "preset=", 7 ) )
713 query_preset( strchr( pname, '=' ) + 1 );
720 query_services( repo, consumer_type );
721 query_services( repo, filter_type );
722 query_services( repo, producer_type );
723 query_services( repo, transition_type );
724 fprintf( stderr, "# You can query the metadata for a specific service using:\n"
725 "# -query <type>=<identifer>\n"
726 "# where <type> is one of: consumer, filter, producer, or transition.\n" );
730 else if ( !strcmp( argv[ i ], "-silent" ) )
734 else if ( !strcmp( argv[ i ], "-verbose" ) )
736 mlt_log_set_level( MLT_LOG_VERBOSE );
738 else if ( !strcmp( argv[ i ], "-version" ) || !strcmp( argv[ i ], "--version" ) )
740 fprintf( stderr, "MLT %s " VERSION "\n"
741 "Copyright (C) 2002-2011 Ushodaya Enterprises Limited\n"
742 "<http://www.mltframework.org/>\n"
743 "This is free software; see the source for copying conditions. There is NO\n"
744 "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
745 basename( argv[0] ) );
748 else if ( !strcmp( argv[ i ], "-debug" ) )
750 mlt_log_set_level( MLT_LOG_DEBUG );
754 // Create profile if not set explicitly
755 if ( getenv( "MLT_PROFILE" ) )
756 profile = mlt_profile_init( NULL );
757 if ( profile == NULL )
758 profile = mlt_profile_init( NULL );
760 profile->is_explicit = 1;
762 // Look for the consumer option to load profile settings from consumer properties
763 backup_profile = mlt_profile_clone( profile );
764 load_consumer( &consumer, profile, argc, argv );
766 // If the consumer changed the profile, then it is explicit.
767 if ( backup_profile && !profile->is_explicit && (
768 profile->width != backup_profile->width ||
769 profile->height != backup_profile->height ||
770 profile->sample_aspect_num != backup_profile->sample_aspect_num ||
771 profile->sample_aspect_den != backup_profile->sample_aspect_den ||
772 profile->frame_rate_den != backup_profile->frame_rate_den ||
773 profile->frame_rate_num != backup_profile->frame_rate_num ||
774 profile->colorspace != backup_profile->colorspace ) )
775 profile->is_explicit = 1;
776 mlt_profile_close( backup_profile );
780 melt = mlt_factory_producer( profile, "melt", &argv[ 1 ] );
784 // Generate an automatic profile if needed.
785 if ( ! profile->is_explicit )
787 guess_profile( melt, profile );
788 mlt_producer_close( melt );
789 melt = mlt_factory_producer( profile, "melt", &argv[ 1 ] );
792 // Reload the consumer with the fully qualified profile.
793 // The producer or guess_profile could have changed the profile.
794 load_consumer( &consumer, profile, argc, argv );
796 // If we have no consumer, default to sdl
797 if ( store == NULL && consumer == NULL )
798 consumer = create_consumer( profile, NULL );
801 // Set transport properties on consumer and produder
802 if ( consumer != NULL && melt != NULL )
804 mlt_properties_set_data( MLT_CONSUMER_PROPERTIES( consumer ), "transport_producer", melt, 0, NULL, NULL );
805 mlt_properties_set_data( MLT_PRODUCER_PROPERTIES( melt ), "transport_consumer", consumer, 0, NULL, NULL );
807 mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( consumer ), "progress", is_progress );
809 mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( consumer ), "silent", is_silent );
812 if ( argc > 1 && melt != NULL && mlt_producer_get_length( melt ) > 0 )
814 // Parse the arguments
815 for ( i = 1; i < argc; i ++ )
817 if ( !strcmp( argv[ i ], "-jack" ) )
819 setup_jack_transport( consumer, profile );
821 else if ( !strcmp( argv[ i ], "-serialise" ) )
823 if ( store != stdout )
829 fprintf( store, "%s\n", argv[ i ] );
833 while ( argv[ i ] != NULL && argv[ i ][ 0 ] != '-' )
836 fprintf( store, "%s\n", argv[ i ] );
844 if ( consumer != NULL && store == NULL )
846 // Get melt's properties
847 mlt_properties melt_props = MLT_PRODUCER_PROPERTIES( melt );
849 // Get the last group
850 mlt_properties group = mlt_properties_get_data( melt_props, "group", 0 );
852 // Apply group settings
853 mlt_properties properties = MLT_CONSUMER_PROPERTIES( consumer );
854 mlt_properties_inherit( properties, group );
856 // Connect consumer to melt
857 mlt_consumer_connect( consumer, MLT_PRODUCER_SERVICE( melt ) );
859 // Start the consumer
860 mlt_events_listen( properties, consumer, "consumer-fatal-error", ( mlt_listener )on_fatal_error );
861 if ( mlt_consumer_start( consumer ) == 0 )
863 // Transport functionality
864 transport( melt, consumer );
867 mlt_consumer_stop( consumer );
870 else if ( store != NULL && store != stdout && name != NULL )
872 fprintf( stderr, "Project saved as %s.\n", name );
878 show_usage( argv[0] );
881 // Close the producer
883 mlt_producer_close( melt );
885 // Close the consumer
886 if ( consumer != NULL )
887 mlt_consumer_close( consumer );
890 mlt_profile_close( profile );
894 mlt_factory_close( );