mlt_producer create_tracks( int argc, char **argv ) { // Create the field mlt_field field = mlt_field_init( ); // Obtain the multitrack mlt_multitrack multitrack = mlt_field_multitrack( field ); // Obtain the tractor mlt_tractor tractor = mlt_field_tractor( field ); // Obtain a composite transition mlt_transition transition = mlt_factory_transition( "composite", "10%,10%:15%x15%" ); // Create track 0 mlt_producer track0 = create_playlist( argc, argv ); // Get the length of track0 mlt_position length = mlt_producer_get_playtime( track0 ); // Create the watermark track mlt_producer track1 = mlt_factory_producer( NULL, "pango:" ); // Get the properties of track1 mlt_properties properties = mlt_producer_properties( track1 ); // Set the properties mlt_properties_set( properties, "text", "Hello\nWorld" ); mlt_properties_set_position( properties, "in", 0 ); mlt_properties_set_position( properties, "out", length - 1 ); mlt_properties_set_position( properties, "length", length ); // Now set the properties on the transition properties = mlt_transition_properties( transition ); mlt_properties_set_position( properties, "in", 0 ); mlt_properties_set_position( properties, "out", length - 1 ); // Add our tracks to the multitrack mlt_multitrack_connect( multitrack, track0, 0 ); mlt_multitrack_connect( multitrack, track1, 1 ); // Now plant the transition mlt_field_plant_transition( field, transition, 0, 1 ); // Now set the properties on the transition properties = mlt_tractor_properties( tractor ); // Ensure clean up and set properties correctly mlt_properties_set_data( properties, "multitrack", multitrack, 0, ( mlt_destructor )mlt_multitrack_close, NULL ); mlt_properties_set_data( properties, "field", field, 0, ( mlt_destructor )mlt_field_close, NULL ); mlt_properties_set_data( properties, "track0", track0, 0, ( mlt_destructor )mlt_producer_close, NULL ); mlt_properties_set_data( properties, "track1", track1, 0, ( mlt_destructor )mlt_producer_close, NULL ); mlt_properties_set_data( properties, "transition", transition, 0, ( mlt_destructor )mlt_transition_close, NULL ); mlt_properties_set_position( properties, "length", length ); mlt_properties_set_position( properties, "out", length - 1 ); // Return the tractor return mlt_tractor_producer( tractor ); }
int mlt_multitrack_insert( mlt_multitrack self, mlt_producer producer, int track ) { if ( track >= self->count ) return mlt_multitrack_connect( self, producer, track ); // Connect to the producer to ourselves at the specified track int result = mlt_service_insert_producer( MLT_MULTITRACK_SERVICE( self ), MLT_PRODUCER_SERVICE( producer ), track ); if ( result == 0 ) { // Resize the producer list if needed. if ( self->count + 1 > self->size ) { int new_size = self->size + 10; self->list = realloc( self->list, new_size * sizeof( mlt_track ) ); if ( self->list ) { memset( &self->list[ self->size ], 0, new_size - self->size ); self->size = new_size; } } if ( self->list ) { // Move all of the list elements following track N down by 1. memmove( &self->list[ track + 1 ], &self->list[ track ], ( self->count - track ) * sizeof ( mlt_track ) ); self->count ++; // Assign the track in our list. self->list[ track ] = malloc( sizeof( struct mlt_track_s ) ); self->list[ track ]->producer = producer; self->list[ track ]->event = mlt_events_listen( MLT_PRODUCER_PROPERTIES( producer ), self, "producer-changed", ( mlt_listener )mlt_multitrack_listener ); mlt_properties_inc_ref( MLT_PRODUCER_PROPERTIES( producer ) ); mlt_event_inc_ref( self->list[ track ]->event ); // TODO: Move this into producer_avformat.c when mlt_events broadcasting is available. if ( self->count > mlt_service_cache_get_size( MLT_MULTITRACK_SERVICE( self ), "producer_avformat" ) ) mlt_service_cache_set_size( MLT_MULTITRACK_SERVICE( self ), "producer_avformat", self->count + 1 ); // Refresh our stats mlt_multitrack_refresh( self ); } else { result = -1; } } return result; }
int main( int argc, char **argv ) { char temp[ 132 ]; char *file1 = NULL; char *file2 = NULL; char *wipe = NULL; mlt_factory_init( "../modules" ); if ( argc < 4 ) { fprintf( stderr, "usage: luma file1.mpeg file2.mpeg wipe.pgm\n" ); return 1; } else { file1 = argv[ 1 ]; file2 = argv[ 2 ]; wipe = argv[ 3 ]; } // Start the consumer... mlt_consumer consumer = mlt_factory_consumer( "bluefish", "NTSC" ); // Create the producer(s) mlt_producer dv1 = mlt_factory_producer( "mcmpeg", file1 ); mlt_producer dv2 = mlt_factory_producer( "mcmpeg", file2 ); mlt_playlist playlist1 = mlt_playlist_init(); mlt_playlist_append_io( playlist1, dv1, 0.0, 5.0 ); mlt_playlist playlist2 = mlt_playlist_init(); mlt_playlist_blank( playlist2, 2.9 ); mlt_playlist_append( playlist2, dv2 ); // Register producers(s) with a multitrack object mlt_multitrack multitrack = mlt_multitrack_init( ); mlt_multitrack_connect( multitrack, mlt_playlist_producer( playlist1 ), 0 ); mlt_multitrack_connect( multitrack, mlt_playlist_producer( playlist2 ), 1 ); // Define a transition mlt_transition transition = mlt_factory_transition( "luma", wipe ); mlt_properties_set( mlt_transition_properties( transition ), "filename", wipe ); mlt_properties_set_double( mlt_transition_properties( transition ), "softness", 0.1 ); mlt_transition_connect( transition, mlt_multitrack_service( multitrack ), 0, 1 ); mlt_transition_set_in_and_out( transition, 3.0, 5.0 ); // Buy a tractor and connect it to the filter mlt_tractor tractor = mlt_tractor_init( ); mlt_tractor_connect( tractor, mlt_transition_service( transition ) ); // Connect the tractor to the consumer mlt_consumer_connect( consumer, mlt_tractor_service( tractor ) ); // Do stuff until we're told otherwise... fprintf( stderr, "Press return to continue\n" ); fgets( temp, 132, stdin ); // Close everything... mlt_consumer_close( consumer ); mlt_tractor_close( tractor ); mlt_transition_close( transition ); mlt_multitrack_close( multitrack ); mlt_playlist_close( playlist1 ); mlt_playlist_close( playlist2 ); mlt_producer_close( dv1 ); mlt_producer_close( dv2 ); return 0; }
int mlt_tractor_set_track( mlt_tractor self, mlt_producer producer, int index ) { return mlt_multitrack_connect( mlt_tractor_multitrack( self ), producer, index ); }
int main( int argc, char **argv ) { char temp[ 132 ]; char *file1 = NULL; char *text = NULL; mlt_factory_init( "../modules" ); if ( argc < 3 ) { fprintf( stderr, "usage: pango file.mpeg text_to_display\n" ); return 1; } else { file1 = argv[ 1 ]; text = argv[ 2 ]; } // Start the consumer... mlt_consumer consumer = mlt_factory_consumer( "bluefish", "NTSC" ); // Create the producer(s) mlt_playlist pl1 = mlt_playlist_init(); mlt_producer dv1 = mlt_factory_producer( "mcmpeg", file1 ); mlt_playlist_append( pl1, dv1 ); mlt_playlist pl2 = mlt_playlist_init(); mlt_producer title = mlt_factory_producer( "pango", NULL ); //"<span font_desc=\"Sans Bold 36\">Mutton <span font_desc=\"Luxi Serif Bold Oblique 36\">Lettuce</span> Tomato</span>" ); mlt_playlist_append( pl2, title ); mlt_properties_set( mlt_producer_properties( title ), "family", "Sans" ); mlt_properties_set( mlt_producer_properties( title ), "size", "36" ); mlt_properties_set( mlt_producer_properties( title ), "weight", "700" ); mlt_properties_set( mlt_producer_properties( title ), "text", text ); mlt_properties_set_int( mlt_producer_properties( title ), "bgcolor", 0x0000007f ); mlt_properties_set_int( mlt_producer_properties( title ), "pad", 8 ); mlt_properties_set_int( mlt_producer_properties( title ), "align", 1 ); mlt_properties_set_int( mlt_producer_properties( title ), "x", 200 ); mlt_properties_set_int( mlt_producer_properties( title ), "y", 40 ); mlt_properties_set_double( mlt_producer_properties( title ), "mix", 0.8 ); // Register producers(s) with a multitrack object mlt_multitrack multitrack = mlt_multitrack_init( ); mlt_multitrack_connect( multitrack, mlt_playlist_producer( pl1 ), 0 ); mlt_multitrack_connect( multitrack, mlt_playlist_producer( pl2 ), 1 ); // Define a transition mlt_transition transition = mlt_factory_transition( "composite", NULL ); mlt_transition_connect( transition, mlt_multitrack_service( multitrack ), 0, 1 ); mlt_transition_set_in_and_out( transition, 0.0, 9999.0 ); // Buy a tractor and connect it to the filter mlt_tractor tractor = mlt_tractor_init( ); mlt_tractor_connect( tractor, mlt_transition_service( transition ) ); // Connect the tractor to the consumer mlt_consumer_connect( consumer, mlt_tractor_service( tractor ) ); // Do stuff until we're told otherwise... fprintf( stderr, "Press return to continue\n" ); fgets( temp, 132, stdin ); // Close everything... mlt_consumer_close( consumer ); mlt_tractor_close( tractor ); mlt_transition_close( transition ); mlt_multitrack_close( multitrack ); mlt_playlist_close( pl1 ); mlt_playlist_close( pl2 ); mlt_producer_close( dv1 ); mlt_producer_close( title ); return 0; }