5 #include <framework/mlt.h>
9 mlt_producer create_producer( char *file )
11 mlt_producer result = NULL;
13 // 1st Line preferences
14 if ( strstr( file, ".mpg" ) )
15 result = mlt_factory_producer( "mcmpeg", file );
16 else if ( strstr( file, ".mpeg" ) )
17 result = mlt_factory_producer( "mcmpeg", file );
18 else if ( strstr( file, ".dv" ) )
19 result = mlt_factory_producer( "mcdv", file );
20 else if ( strstr( file, ".dif" ) )
21 result = mlt_factory_producer( "mcdv", file );
22 else if ( strstr( file, ".jpg" ) )
23 result = mlt_factory_producer( "pixbuf", file );
24 else if ( strstr( file, ".JPG" ) )
25 result = mlt_factory_producer( "pixbuf", file );
26 else if ( strstr( file, ".jpeg" ) )
27 result = mlt_factory_producer( "pixbuf", file );
28 else if ( strstr( file, ".png" ) )
29 result = mlt_factory_producer( "pixbuf", file );
32 if ( result == NULL && strstr( file, ".dv" ) )
33 result = mlt_factory_producer( "libdv", file );
34 else if ( result == NULL && strstr( file, ".dif" ) )
35 result = mlt_factory_producer( "libdv", file );
40 void transport_action( mlt_producer producer, char *value )
42 mlt_properties properties = mlt_producer_properties( producer );
47 mlt_properties_set_int( properties, "done", 1 );
50 mlt_producer_set_speed( producer, 1 );
51 mlt_producer_seek( producer, 0 );
54 mlt_producer_set_speed( producer, -5 );
57 mlt_producer_set_speed( producer, -2.5 );
60 mlt_producer_set_speed( producer, -1 );
63 mlt_producer_set_speed( producer, -0.5 );
66 mlt_producer_set_speed( producer, 0 );
69 mlt_producer_set_speed( producer, 0.5 );
72 mlt_producer_set_speed( producer, 1 );
75 mlt_producer_set_speed( producer, 2.5 );
78 mlt_producer_set_speed( producer, 5 );
83 mlt_consumer create_consumer( char *id, mlt_producer producer )
85 char *arg = strchr( id, ':' );
88 mlt_consumer consumer = mlt_factory_consumer( id, arg );
89 if ( consumer != NULL )
91 mlt_properties properties = mlt_consumer_properties( consumer );
92 mlt_properties_set_data( properties, "transport_callback", transport_action, 0, NULL, NULL );
93 mlt_properties_set_data( properties, "transport_producer", producer, 0, NULL, NULL );
98 void track_service( mlt_field field, void *service, mlt_destructor destructor )
100 mlt_properties properties = mlt_field_properties( field );
101 int registered = mlt_properties_get_int( properties, "registered" );
102 char *key = mlt_properties_get( properties, "registered" );
103 mlt_properties_set_data( properties, key, service, 0, destructor, NULL );
104 mlt_properties_set_int( properties, "registered", ++ registered );
107 mlt_filter create_filter( mlt_field field, char *id, int track )
109 char *arg = strchr( id, ':' );
112 mlt_filter filter = mlt_factory_filter( id, arg );
113 if ( filter != NULL )
115 mlt_field_plant_filter( field, filter, track );
116 track_service( field, filter, ( mlt_destructor )mlt_filter_close );
121 void set_properties( mlt_service service, char *namevalue )
123 mlt_properties properties = mlt_service_properties( service );
124 mlt_properties_parse( properties, namevalue );
127 void transport( mlt_producer producer )
129 mlt_properties properties = mlt_producer_properties( producer );
132 fprintf( stderr, "Press 'q' to continue\n" );
133 while( mlt_properties_get_int( properties, "done" ) == 0 )
135 int value = term_read( );
137 transport_action( producer, ( char * )&value );
141 int main( int argc, char **argv )
144 mlt_service service = NULL;
145 mlt_consumer consumer = NULL;
146 mlt_multitrack multitrack = NULL;
147 mlt_producer producer = NULL;
148 mlt_playlist playlist = NULL;
149 mlt_field field = NULL;
151 // Construct the factory
152 mlt_factory_init( getenv( "MLT_REPOSITORY" ) );
155 playlist = mlt_playlist_init( );
157 // Construct the field
158 field = mlt_field_init( );
159 mlt_properties properties = mlt_field_properties( field );
160 mlt_properties_set_int( properties, "registered", 0 );
162 // Get the multitrack from the field
163 multitrack = mlt_field_multitrack( field );
165 // Parse the arguments
166 for ( i = 1; i < argc; i ++ )
168 if ( !strcmp( argv[ i ], "-consumer" ) )
170 consumer = create_consumer( argv[ ++ i ], mlt_multitrack_producer( multitrack ) );
171 if ( consumer != NULL )
172 service = mlt_consumer_service( consumer );
174 else if ( !strcmp( argv[ i ], "-filter" ) )
176 mlt_filter filter = create_filter( field, argv[ ++ i ], 0 );
177 if ( filter != NULL )
178 service = mlt_filter_service( filter );
180 else if ( !strstr( argv[ i ], "=" ) )
182 if ( producer != NULL )
183 mlt_playlist_append( playlist, producer );
184 producer = create_producer( argv[ i ] );
185 if ( producer != NULL )
186 service = mlt_producer_service( producer );
190 set_properties( service, argv[ i ] );
194 // If we have no consumer, default to sdl
195 if ( consumer == NULL )
196 consumer = create_consumer( "sdl", mlt_multitrack_producer( multitrack ) );
198 // Connect producer to playlist
199 if ( producer != NULL )
200 mlt_playlist_append( playlist, producer );
202 // Connect multitrack to producer
203 mlt_multitrack_connect( multitrack, mlt_playlist_producer( playlist ), 0 );
205 // Connect consumer to tractor
206 mlt_consumer_connect( consumer, mlt_field_service( field ) );
208 // Transport functionality
209 transport( mlt_multitrack_producer( multitrack ) );
211 // Close the services
212 mlt_consumer_close( consumer );
213 mlt_field_close( field );
214 mlt_producer_close( producer );
217 mlt_factory_close( );