3 #include <framework/mlt.h>
5 mlt_producer create_playlist( int argc, char **argv )
7 // We're creating a playlist here
8 mlt_playlist playlist = mlt_playlist_init( );
10 // We need the playlist properties to ensure clean up
11 mlt_properties properties = mlt_playlist_properties( playlist );
13 // Loop through each of the arguments
15 for ( i = 1; i < argc; i ++ )
17 // Definie the unique key
20 // Create the producer
21 mlt_producer producer = mlt_factory_producer( NULL, argv[ i ] );
23 // Add it to the playlist
24 mlt_playlist_append( playlist, producer );
26 // Create a unique key for this producer
27 sprintf( key, "producer%d", i );
29 // Now we need to ensure the producers are destroyed
30 mlt_properties_set_data( properties, key, producer, 0, ( mlt_destructor )mlt_producer_close, NULL );
33 // Return the playlist as a producer
34 return mlt_playlist_producer( playlist );
37 mlt_producer create_tracks( int argc, char **argv )
40 mlt_field field = mlt_field_init( );
42 // Obtain the multitrack
43 mlt_multitrack multitrack = mlt_field_multitrack( field );
46 mlt_tractor tractor = mlt_field_tractor( field );
48 // Obtain a composite transition
49 mlt_transition transition = mlt_factory_transition( "composite", "10%,10%:15%x15%" );
52 mlt_producer track0 = create_playlist( argc, argv );
54 // Get the length of track0
55 mlt_position length = mlt_producer_get_playtime( track0 );
57 // Create the watermark track
58 mlt_producer track1 = mlt_factory_producer( "fezzik", "pango" );
60 // Get the properties of track1
61 mlt_properties properties = mlt_producer_properties( track1 );
64 mlt_properties_set( properties, "text", "Hello\nWorld" );
65 mlt_properties_set_position( properties, "in", 0 );
66 mlt_properties_set_position( properties, "out", length - 1 );
67 mlt_properties_set_position( properties, "length", length );
69 // Now set the properties on the transition
70 properties = mlt_transition_properties( transition );
71 mlt_properties_set_position( properties, "in", 0 );
72 mlt_properties_set_position( properties, "out", length - 1 );
74 // Add our tracks to the multitrack
75 mlt_multitrack_connect( multitrack, track0, 0 );
76 mlt_multitrack_connect( multitrack, track1, 1 );
78 // Now plant the transition
79 mlt_field_plant_transition( field, transition, 0, 1 );
81 // Now set the properties on the transition
82 properties = mlt_tractor_properties( tractor );
84 // Ensure clean up and set properties correctly
85 mlt_properties_set_data( properties, "multitrack", multitrack, 0, ( mlt_destructor )mlt_multitrack_close, NULL );
86 mlt_properties_set_data( properties, "field", field, 0, ( mlt_destructor )mlt_field_close, NULL );
87 mlt_properties_set_data( properties, "track0", track0, 0, ( mlt_destructor )mlt_producer_close, NULL );
88 mlt_properties_set_data( properties, "track1", track1, 0, ( mlt_destructor )mlt_producer_close, NULL );
89 mlt_properties_set_data( properties, "transition", transition, 0, ( mlt_destructor )mlt_transition_close, NULL );
90 mlt_properties_set_position( properties, "length", length );
91 mlt_properties_set_position( properties, "out", length - 1 );
94 return mlt_tractor_producer( tractor );
97 int main( int argc, char **argv )
99 // Initialise the factory
100 if ( mlt_factory_init( NULL ) == 0 )
102 // Create the default consumer
103 mlt_consumer hello = mlt_factory_consumer( NULL, NULL );
105 // Create a producer using the default normalising selecter
106 mlt_producer world = create_tracks( argc, argv );
108 // Connect the producer to the consumer
109 mlt_consumer_connect( hello, mlt_producer_service( world ) );
111 // Start the consumer
112 mlt_consumer_start( hello );
114 // Wait for the consumer to terminate
115 while( !mlt_consumer_is_stopped( hello ) )
118 // Close the consumer
119 mlt_consumer_close( hello );
121 // Close the producer
122 mlt_producer_close( world );
125 mlt_factory_close( );
129 // Report an error during initialisation
130 fprintf( stderr, "Unable to locate factory modules\n" );