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
);
30 else if ( strstr( file
, ".txt" ) )
31 result
= mlt_factory_producer( "pango", file
);
34 if ( result
== NULL
&& strstr( file
, ".dv" ) )
35 result
= mlt_factory_producer( "libdv", file
);
36 else if ( result
== NULL
&& strstr( file
, ".dif" ) )
37 result
= mlt_factory_producer( "libdv", file
);
41 result
= mlt_factory_producer( "ffmpeg", file
);
46 void transport_action( mlt_producer producer
, char *value
)
48 mlt_properties properties
= mlt_producer_properties( producer
);
49 mlt_multitrack multitrack
= mlt_properties_get_data( properties
, "multitrack", NULL
);
51 if ( strlen( value
) == 1 )
56 mlt_properties_set_int( properties
, "done", 1 );
59 mlt_producer_set_speed( producer
, 1 );
60 mlt_producer_seek( producer
, 0 );
63 mlt_producer_set_speed( producer
, -10 );
66 mlt_producer_set_speed( producer
, -5 );
69 mlt_producer_set_speed( producer
, -2 );
72 mlt_producer_set_speed( producer
, -1 );
75 mlt_producer_set_speed( producer
, 0 );
78 mlt_producer_set_speed( producer
, 1 );
81 mlt_producer_set_speed( producer
, 2 );
84 mlt_producer_set_speed( producer
, 5 );
87 mlt_producer_set_speed( producer
, 10 );
90 if ( multitrack
!= NULL
)
92 mlt_timecode time
= mlt_multitrack_clip( multitrack
, mlt_whence_relative_current
, -1 );
93 mlt_producer_seek( producer
, time
);
97 if ( multitrack
!= NULL
)
99 mlt_timecode time
= mlt_multitrack_clip( multitrack
, mlt_whence_relative_current
, 0 );
100 mlt_producer_seek( producer
, time
);
104 if ( multitrack
!= NULL
)
106 mlt_timecode time
= mlt_multitrack_clip( multitrack
, mlt_whence_relative_current
, 1 );
107 mlt_producer_seek( producer
, time
);
114 mlt_consumer
create_consumer( char *id
, mlt_producer producer
)
116 char *arg
= strchr( id
, ':' );
119 mlt_consumer consumer
= mlt_factory_consumer( id
, arg
);
120 if ( consumer
!= NULL
)
122 mlt_properties properties
= mlt_consumer_properties( consumer
);
123 mlt_properties_set_data( properties
, "transport_callback", transport_action
, 0, NULL
, NULL
);
124 mlt_properties_set_data( properties
, "transport_producer", producer
, 0, NULL
, NULL
);
129 void track_service( mlt_field field
, void *service
, mlt_destructor destructor
)
131 mlt_properties properties
= mlt_field_properties( field
);
132 int registered
= mlt_properties_get_int( properties
, "registered" );
133 char *key
= mlt_properties_get( properties
, "registered" );
134 mlt_properties_set_data( properties
, key
, service
, 0, destructor
, NULL
);
135 mlt_properties_set_int( properties
, "registered", ++ registered
);
138 mlt_filter
create_filter( mlt_field field
, char *id
, int track
)
140 char *arg
= strchr( id
, ':' );
143 mlt_filter filter
= mlt_factory_filter( id
, arg
);
144 if ( filter
!= NULL
)
146 mlt_field_plant_filter( field
, filter
, track
);
147 track_service( field
, filter
, ( mlt_destructor
)mlt_filter_close
);
152 mlt_transition
create_transition( mlt_field field
, char *id
, int track
)
154 char *arg
= strchr( id
, ':' );
157 mlt_transition transition
= mlt_factory_transition( id
, arg
);
158 if ( transition
!= NULL
)
160 mlt_field_plant_transition( field
, transition
, track
, track
+ 1 );
161 track_service( field
, transition
, ( mlt_destructor
)mlt_transition_close
);
166 void set_properties( mlt_properties properties
, char *namevalue
)
168 mlt_properties_parse( properties
, namevalue
);
171 void transport( mlt_producer producer
)
173 mlt_properties properties
= mlt_producer_properties( producer
);
177 fprintf( stderr
, "+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+\n" );
178 fprintf( stderr
, "|1=-10| |2= -5| |3= -2| |4= -1| |5= 0| |6= 1| |7= 2| |8= 5| |9= 10|\n" );
179 fprintf( stderr
, "+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+\n" );
181 fprintf( stderr
, "+---------------------------------------------------------------------+\n" );
182 fprintf( stderr
, "| j = previous, k = restart current, l = next |\n" );
183 fprintf( stderr
, "| 0 = restart, q = quit |\n" );
184 fprintf( stderr
, "+---------------------------------------------------------------------+\n" );
186 while( mlt_properties_get_int( properties
, "done" ) == 0 )
188 int value
= term_read( );
190 transport_action( producer
, ( char * )&value
);
194 int main( int argc
, char **argv
)
198 mlt_consumer consumer
= NULL
;
199 mlt_producer producer
= NULL
;
200 mlt_playlist playlist
= mlt_playlist_init( );
201 mlt_properties group
= mlt_properties_new( );
202 mlt_properties properties
= group
;
203 mlt_field field
= mlt_field_init( );
204 mlt_properties field_properties
= mlt_field_properties( field
);
205 mlt_multitrack multitrack
= mlt_field_multitrack( field
);
207 // Construct the factory
208 mlt_factory_init( getenv( "MLT_REPOSITORY" ) );
210 // We need to track the number of registered filters
211 mlt_properties_set_int( field_properties
, "registered", 0 );
213 // Parse the arguments
214 for ( i
= 1; i
< argc
; i
++ )
216 if ( !strcmp( argv
[ i
], "-consumer" ) )
218 consumer
= create_consumer( argv
[ ++ i
], mlt_multitrack_producer( multitrack
) );
219 if ( consumer
!= NULL
)
221 properties
= mlt_consumer_properties( consumer
);
222 mlt_properties_inherit( properties
, group
);
225 else if ( !strcmp( argv
[ i
], "-group" ) )
227 if ( mlt_properties_count( group
) != 0 )
229 mlt_properties_close( group
);
230 group
= mlt_properties_new( );
235 else if ( !strcmp( argv
[ i
], "-filter" ) )
237 mlt_filter filter
= create_filter( field
, argv
[ ++ i
], track
);
238 if ( filter
!= NULL
)
240 properties
= mlt_filter_properties( filter
);
241 mlt_properties_inherit( properties
, group
);
244 else if ( !strcmp( argv
[ i
], "-transition" ) )
246 mlt_transition transition
= create_transition( field
, argv
[ ++ i
], track
);
247 if ( transition
!= NULL
)
249 properties
= mlt_transition_properties( transition
);
250 mlt_properties_inherit( properties
, group
);
253 else if ( !strcmp( argv
[ i
], "-blank" ) )
255 if ( producer
!= NULL
)
256 mlt_playlist_append( playlist
, producer
);
258 mlt_playlist_blank( playlist
, atof( argv
[ ++ i
] ) );
260 else if ( !strcmp( argv
[ i
], "-track" ) )
262 if ( producer
!= NULL
)
263 mlt_playlist_append( playlist
, producer
);
265 mlt_multitrack_connect( multitrack
, mlt_playlist_producer( playlist
), track
++ );
266 playlist
= mlt_playlist_init( );
268 else if ( !strstr( argv
[ i
], "=" ) )
270 if ( producer
!= NULL
)
271 mlt_playlist_append( playlist
, producer
);
272 producer
= create_producer( argv
[ i
] );
273 if ( producer
!= NULL
)
275 properties
= mlt_producer_properties( producer
);
276 mlt_properties_inherit( properties
, group
);
281 set_properties( properties
, argv
[ i
] );
285 // Connect producer to playlist
286 if ( producer
!= NULL
)
287 mlt_playlist_append( playlist
, producer
);
290 // We must have a producer at this point
291 if ( mlt_playlist_count( playlist
) > 0 )
293 // If we have no consumer, default to sdl
294 if ( consumer
== NULL
)
296 consumer
= create_consumer( "sdl", mlt_multitrack_producer( multitrack
) );
297 if ( consumer
!= NULL
)
299 properties
= mlt_consumer_properties( consumer
);
300 mlt_properties_inherit( properties
, group
);
304 // Connect multitrack to producer
305 mlt_multitrack_connect( multitrack
, mlt_playlist_producer( playlist
), track
);
307 // Connect consumer to tractor
308 mlt_consumer_connect( consumer
, mlt_field_service( field
) );
310 // Transport functionality
311 transport( mlt_multitrack_producer( multitrack
) );
313 // Close the services
314 mlt_consumer_close( consumer
);
315 mlt_producer_close( producer
);
319 fprintf( stderr
, "Usage: inigo [ -group [ name=value ]* ]\n"
320 " [ -consumer id[:arg] [ name=value ]* ]\n"
321 " [ -filter id[:arg] [ name=value ] * ]\n"
322 " [ -transition id[:arg] [ name=value ] * ]\n"
324 " [ producer [ name=value ] * ]+\n" );
328 mlt_field_close( field
);
331 mlt_properties_close( group
);
334 mlt_factory_close( );