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 );
39 result = mlt_factory_producer( "ffmpeg", file );
44 void transport_action( mlt_producer producer, char *value )
46 mlt_properties properties = mlt_producer_properties( producer );
47 mlt_multitrack multitrack = mlt_properties_get_data( properties, "multitrack", NULL );
49 if ( strlen( value ) == 1 )
54 mlt_properties_set_int( properties, "done", 1 );
57 mlt_producer_set_speed( producer, 1 );
58 mlt_producer_seek( producer, 0 );
61 mlt_producer_set_speed( producer, -10 );
64 mlt_producer_set_speed( producer, -5 );
67 mlt_producer_set_speed( producer, -2 );
70 mlt_producer_set_speed( producer, -1 );
73 mlt_producer_set_speed( producer, 0 );
76 mlt_producer_set_speed( producer, 1 );
79 mlt_producer_set_speed( producer, 2 );
82 mlt_producer_set_speed( producer, 5 );
85 mlt_producer_set_speed( producer, 10 );
88 if ( multitrack != NULL )
90 mlt_timecode time = mlt_multitrack_clip( multitrack, mlt_whence_relative_current, -1 );
91 mlt_producer_seek( producer, time );
95 if ( multitrack != NULL )
97 mlt_timecode time = mlt_multitrack_clip( multitrack, mlt_whence_relative_current, 0 );
98 mlt_producer_seek( producer, time );
102 if ( multitrack != NULL )
104 mlt_timecode time = mlt_multitrack_clip( multitrack, mlt_whence_relative_current, 1 );
105 mlt_producer_seek( producer, time );
112 mlt_consumer create_consumer( char *id, mlt_producer producer )
114 char *arg = strchr( id, ':' );
117 mlt_consumer consumer = mlt_factory_consumer( id, arg );
118 if ( consumer != NULL )
120 mlt_properties properties = mlt_consumer_properties( consumer );
121 mlt_properties_set_data( properties, "transport_callback", transport_action, 0, NULL, NULL );
122 mlt_properties_set_data( properties, "transport_producer", producer, 0, NULL, NULL );
127 void track_service( mlt_field field, void *service, mlt_destructor destructor )
129 mlt_properties properties = mlt_field_properties( field );
130 int registered = mlt_properties_get_int( properties, "registered" );
131 char *key = mlt_properties_get( properties, "registered" );
132 mlt_properties_set_data( properties, key, service, 0, destructor, NULL );
133 mlt_properties_set_int( properties, "registered", ++ registered );
136 mlt_filter create_filter( mlt_field field, char *id, int track )
138 char *arg = strchr( id, ':' );
141 mlt_filter filter = mlt_factory_filter( id, arg );
142 if ( filter != NULL )
144 mlt_field_plant_filter( field, filter, track );
145 track_service( field, filter, ( mlt_destructor )mlt_filter_close );
150 void set_properties( mlt_properties properties, char *namevalue )
152 mlt_properties_parse( properties, namevalue );
155 void transport( mlt_producer producer )
157 mlt_properties properties = mlt_producer_properties( producer );
161 fprintf( stderr, "+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+\n" );
162 fprintf( stderr, "|1=-10| |2= -5| |3= -2| |4= -1| |5= 0| |6= 1| |7= 2| |8= 5| |9= 10|\n" );
163 fprintf( stderr, "+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+\n" );
165 fprintf( stderr, "+---------------------------------------------------------------------+\n" );
166 fprintf( stderr, "| j = previous, k = restart current, l = next |\n" );
167 fprintf( stderr, "| 0 = restart, q = quit |\n" );
168 fprintf( stderr, "+---------------------------------------------------------------------+\n" );
170 while( mlt_properties_get_int( properties, "done" ) == 0 )
172 int value = term_read( );
174 transport_action( producer, ( char * )&value );
178 int main( int argc, char **argv )
182 mlt_consumer consumer = NULL;
183 mlt_producer producer = NULL;
184 mlt_playlist playlist = NULL;
185 mlt_properties group = mlt_properties_new( );
186 mlt_properties properties = group;
187 mlt_field field = mlt_field_init( );
188 mlt_properties field_properties = mlt_field_properties( field );
189 mlt_multitrack multitrack = mlt_field_multitrack( field );
191 // Construct the factory
192 mlt_factory_init( getenv( "MLT_REPOSITORY" ) );
195 playlist = mlt_playlist_init( );
197 // We need to track the number of registered filters
198 mlt_properties_set_int( field_properties, "registered", 0 );
200 // Parse the arguments
201 for ( i = 1; i < argc; i ++ )
203 if ( !strcmp( argv[ i ], "-consumer" ) )
205 consumer = create_consumer( argv[ ++ i ], mlt_multitrack_producer( multitrack ) );
206 if ( consumer != NULL )
208 properties = mlt_consumer_properties( consumer );
209 mlt_properties_inherit( properties, group );
212 else if ( !strcmp( argv[ i ], "-group" ) )
214 if ( mlt_properties_count( group ) != 0 )
216 mlt_properties_close( group );
217 group = mlt_properties_new( );
222 else if ( !strcmp( argv[ i ], "-filter" ) )
224 mlt_filter filter = create_filter( field, argv[ ++ i ], 0 );
225 if ( filter != NULL )
227 properties = mlt_filter_properties( filter );
228 mlt_properties_inherit( properties, group );
231 else if ( !strcmp( argv[ i ], "-blank" ) )
233 if ( producer != NULL )
234 mlt_playlist_append( playlist, producer );
236 mlt_playlist_blank( playlist, atof( argv[ ++ i ] ) );
238 else if ( !strstr( argv[ i ], "=" ) )
240 if ( producer != NULL )
241 mlt_playlist_append( playlist, producer );
242 producer = create_producer( argv[ i ] );
243 if ( producer != NULL )
245 properties = mlt_producer_properties( producer );
246 mlt_properties_inherit( properties, group );
251 set_properties( properties, argv[ i ] );
255 // Connect producer to playlist
256 if ( producer != NULL )
257 mlt_playlist_append( playlist, producer );
260 // We must have a producer at this point
261 if ( mlt_playlist_count( playlist ) > 0 )
263 // If we have no consumer, default to sdl
264 if ( consumer == NULL )
266 consumer = create_consumer( "sdl", mlt_multitrack_producer( multitrack ) );
267 if ( consumer != NULL )
269 properties = mlt_consumer_properties( consumer );
270 mlt_properties_inherit( properties, group );
274 // Connect multitrack to producer
275 mlt_multitrack_connect( multitrack, mlt_playlist_producer( playlist ), track );
277 // Connect consumer to tractor
278 mlt_consumer_connect( consumer, mlt_field_service( field ) );
280 // Transport functionality
281 transport( mlt_multitrack_producer( multitrack ) );
283 // Close the services
284 mlt_consumer_close( consumer );
285 mlt_producer_close( producer );
289 fprintf( stderr, "Usage: inigo [ -group [ name=value ]* ]\n"
290 " [ -consumer id[:arg] [ name=value ]* ]\n"
291 " [ -filter id[:arg] [ name=value ] * ]\n"
292 " [ producer [ name=value ] * ]+\n" );
296 mlt_field_close( field );
299 mlt_properties_close( group );
302 mlt_factory_close( );