2 * inigo.c -- MLT command line utility
3 * Copyright (C) 2002-2003 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #include <framework/mlt.h>
34 static void transport_action( mlt_producer producer
, char *value
)
36 mlt_properties properties
= MLT_PRODUCER_PROPERTIES( producer
);
37 mlt_multitrack multitrack
= mlt_properties_get_data( properties
, "multitrack", NULL
);
38 mlt_consumer consumer
= mlt_properties_get_data( properties
, "transport_consumer", NULL
);
40 mlt_properties_set_int( properties
, "stats_off", 0 );
42 if ( strlen( value
) == 1 )
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
, -10 );
57 mlt_producer_set_speed( producer
, -5 );
60 mlt_producer_set_speed( producer
, -2 );
63 mlt_producer_set_speed( producer
, -1 );
66 mlt_producer_set_speed( producer
, 0 );
70 mlt_producer_set_speed( producer
, 1 );
73 mlt_producer_set_speed( producer
, 2 );
76 mlt_producer_set_speed( producer
, 5 );
79 mlt_producer_set_speed( producer
, 10 );
82 if ( multitrack
!= NULL
)
85 mlt_position last
= -1;
86 fprintf( stderr
, "\n" );
87 for ( i
= 0; 1; i
++ )
89 mlt_position time
= mlt_multitrack_clip( multitrack
, mlt_whence_relative_start
, i
);
93 fprintf( stderr
, "%d: %d\n", i
, (int)time
);
99 if ( multitrack
!= NULL
)
101 mlt_position time
= mlt_multitrack_clip( multitrack
, mlt_whence_relative_current
, 0 );
102 mlt_producer_seek( producer
, time
);
106 if ( producer
!= NULL
)
108 mlt_position position
= mlt_producer_position( producer
);
109 mlt_producer_seek( producer
, position
- ( mlt_producer_get_fps( producer
) * 60 ) );
113 if ( producer
!= NULL
)
115 mlt_position position
= mlt_producer_position( producer
);
116 mlt_producer_set_speed( producer
, 0 );
117 mlt_producer_seek( producer
, position
- 1 );
121 if ( multitrack
!= NULL
)
123 mlt_position time
= mlt_multitrack_clip( multitrack
, mlt_whence_relative_current
, 1 );
124 mlt_producer_seek( producer
, time
);
128 if ( multitrack
!= NULL
)
130 mlt_position time
= mlt_multitrack_clip( multitrack
, mlt_whence_relative_current
, -1 );
131 mlt_producer_seek( producer
, time
);
135 if ( producer
!= NULL
)
137 mlt_position position
= mlt_producer_position( producer
);
138 if ( mlt_producer_get_speed( producer
) != 0 )
139 mlt_producer_set_speed( producer
, 0 );
141 mlt_producer_seek( producer
, position
+ 1 );
145 if ( producer
!= NULL
)
147 mlt_position position
= mlt_producer_position( producer
);
148 mlt_producer_seek( producer
, position
+ ( mlt_producer_get_fps( producer
) * 60 ) );
153 mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( consumer
), "refresh", 1 );
156 mlt_properties_set_int( properties
, "stats_off", 0 );
159 static mlt_consumer
create_consumer( mlt_profile profile
, char *id
)
161 char *arg
= id
!= NULL ?
strchr( id
, ':' ) : NULL
;
164 mlt_consumer consumer
= mlt_factory_consumer( profile
, id
, arg
);
165 if ( consumer
!= NULL
)
167 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( consumer
);
168 mlt_properties_set_data( properties
, "transport_callback", transport_action
, 0, NULL
, NULL
);
175 static void event_handling( mlt_producer producer
, mlt_consumer consumer
)
179 while ( SDL_PollEvent( &event
) )
184 mlt_properties_set_int( MLT_PRODUCER_PROPERTIES( consumer
), "done", 1 );
188 if ( event
.key
.keysym
.unicode
< 0x80 && event
.key
.keysym
.unicode
> 0 )
190 char keyboard
[ 2 ] = { event
.key
.keysym
.unicode
, 0 };
191 transport_action( producer
, keyboard
);
200 static void transport( mlt_producer producer
, mlt_consumer consumer
)
202 mlt_properties properties
= MLT_PRODUCER_PROPERTIES( producer
);
203 int silent
= mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer
), "silent" );
204 int progress
= mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer
), "progress" );
205 struct timespec tm
= { 0, 40000 };
206 int total_length
= mlt_producer_get_length( producer
);
207 int last_position
= 0;
209 if ( mlt_properties_get_int( properties
, "done" ) == 0 && !mlt_consumer_is_stopped( consumer
) )
211 if ( !silent
&& !progress
)
215 fprintf( stderr
, "+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+\n" );
216 fprintf( stderr
, "|1=-10| |2= -5| |3= -2| |4= -1| |5= 0| |6= 1| |7= 2| |8= 5| |9= 10|\n" );
217 fprintf( stderr
, "+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+\n" );
219 fprintf( stderr
, "+---------------------------------------------------------------------+\n" );
220 fprintf( stderr
, "| H = back 1 minute, L = forward 1 minute |\n" );
221 fprintf( stderr
, "| h = previous frame, l = next frame |\n" );
222 fprintf( stderr
, "| g = start of clip, j = next clip, k = previous clip |\n" );
223 fprintf( stderr
, "| 0 = restart, q = quit, space = play |\n" );
224 fprintf( stderr
, "+---------------------------------------------------------------------+\n" );
227 while( mlt_properties_get_int( properties
, "done" ) == 0 && !mlt_consumer_is_stopped( consumer
) )
229 int value
= ( silent
|| progress
)?
-1 : term_read( );
233 char string
[ 2 ] = { value
, 0 };
234 transport_action( producer
, string
);
238 event_handling( producer
, consumer
);
241 if ( !silent
&& mlt_properties_get_int( properties
, "stats_off" ) == 0 )
245 int current_position
= mlt_producer_position( producer
);
246 if ( current_position
> last_position
)
248 fprintf( stderr
, "Current Frame: %10d, percentage: %10d\r",
249 current_position
, 100 * current_position
/ total_length
);
250 last_position
= current_position
;
255 fprintf( stderr
, "Current Position: %10d\r", (int)mlt_producer_position( producer
) );
260 nanosleep( &tm
, NULL
);
264 fprintf( stderr
, "\n" );
268 static void query_metadata( mlt_repository repo
, mlt_service_type type
, char *typestr
, char *id
)
270 mlt_properties metadata
= mlt_repository_metadata( repo
, type
, id
);
273 char *s
= mlt_properties_serialise_yaml( metadata
);
274 fprintf( stderr
, "%s", s
);
279 fprintf( stderr
, "# No metadata for %s \"%s\"\n", typestr
, id
);
283 static void query_services( mlt_repository repo
, mlt_service_type type
)
285 mlt_properties services
= NULL
;
286 char *typestr
= NULL
;
290 services
= mlt_repository_consumers( repo
);
291 typestr
= "consumers";
294 services
= mlt_repository_filters( repo
);
298 services
= mlt_repository_producers( repo
);
299 typestr
= "producers";
301 case transition_type
:
302 services
= mlt_repository_transitions( repo
);
303 typestr
= "transitions";
308 fprintf( stderr
, "---\n%s:\n", typestr
);
312 for ( j
= 0; j
< mlt_properties_count( services
); j
++ )
313 fprintf( stderr
, " - %s\n", mlt_properties_get_name( services
, j
) );
315 fprintf( stderr
, "...\n" );
318 int main( int argc
, char **argv
)
321 mlt_consumer consumer
= NULL
;
322 mlt_producer inigo
= NULL
;
325 struct sched_param scp
;
326 mlt_profile profile
= NULL
;
328 // Use realtime scheduling if possible
329 memset( &scp
, '\0', sizeof( scp
) );
330 scp
.sched_priority
= sched_get_priority_max( SCHED_FIFO
) - 1;
332 sched_setscheduler( 0, SCHED_FIFO
, &scp
);
335 // Construct the factory
336 mlt_repository repo
= mlt_factory_init( NULL
);
338 for ( i
= 1; i
< argc
; i
++ )
340 // Check for serialisation switch
341 if ( !strcmp( argv
[ i
], "-serialise" ) )
344 if ( name
!= NULL
&& strstr( name
, ".inigo" ) )
345 store
= fopen( name
, "w" );
348 if ( name
== NULL
|| name
[0] == '-' )
353 // Look for the profile option
354 else if ( !strcmp( argv
[ i
], "-profile" ) )
356 const char *pname
= argv
[ ++ i
];
357 if ( pname
&& pname
[0] != '-' )
358 profile
= mlt_profile_init( pname
);
360 // Look for the query option
361 else if ( !strcmp( argv
[ i
], "-query" ) )
363 const char *pname
= argv
[ ++ i
];
364 if ( pname
&& pname
[0] != '-' )
366 if ( !strcmp( pname
, "consumers" ) || !strcmp( pname
, "consumer" ) )
367 query_services( repo
, consumer_type
);
368 else if ( !strcmp( pname
, "filters" ) || !strcmp( pname
, "filter" ) )
369 query_services( repo
, filter_type
);
370 else if ( !strcmp( pname
, "producers" ) || !strcmp( pname
, "producer" ) )
371 query_services( repo
, producer_type
);
372 else if ( !strcmp( pname
, "transitions" ) || !strcmp( pname
, "transition" ) )
373 query_services( repo
, transition_type
);
375 else if ( !strncmp( pname
, "consumer=", 9 ) )
376 query_metadata( repo
, consumer_type
, "consumer", strchr( pname
, '=' ) + 1 );
377 else if ( !strncmp( pname
, "filter=", 7 ) )
378 query_metadata( repo
, filter_type
, "filter", strchr( pname
, '=' ) + 1 );
379 else if ( !strncmp( pname
, "producer=", 9 ) )
380 query_metadata( repo
, producer_type
, "producer", strchr( pname
, '=' ) + 1 );
381 else if ( !strncmp( pname
, "transition=", 11 ) )
382 query_metadata( repo
, transition_type
, "transition", strchr( pname
, '=' ) + 1 );
389 query_services( repo
, consumer_type
);
390 query_services( repo
, filter_type
);
391 query_services( repo
, producer_type
);
392 query_services( repo
, transition_type
);
393 fprintf( stderr
, "# You can query the metadata for a specific service using:\n"
394 "# -query <type>=<identifer>\n"
395 "# where <type> is one of: consumer, filter, producer, or transition.\n" );
401 // Create profile if not set explicitly
402 if ( profile
== NULL
)
403 profile
= mlt_profile_init( NULL
);
405 // Look for the consumer option
406 for ( i
= 1; i
< argc
; i
++ )
408 if ( !strcmp( argv
[ i
], "-consumer" ) )
410 consumer
= create_consumer( profile
, argv
[ ++ i
] );
413 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( consumer
);
414 while ( argv
[ i
+ 1 ] != NULL
&& strstr( argv
[ i
+ 1 ], "=" ) )
415 mlt_properties_parse( properties
, argv
[ ++ i
] );
420 // If we have no consumer, default to sdl
421 if ( store
== NULL
&& consumer
== NULL
)
422 consumer
= create_consumer( profile
, NULL
);
424 // Get inigo producer
426 inigo
= mlt_factory_producer( profile
, "inigo", &argv
[ 1 ] );
428 // Set transport properties on consumer and produder
429 if ( consumer
!= NULL
&& inigo
!= NULL
)
431 mlt_properties_set_data( MLT_CONSUMER_PROPERTIES( consumer
), "transport_producer", inigo
, 0, NULL
, NULL
);
432 mlt_properties_set_data( MLT_PRODUCER_PROPERTIES( inigo
), "transport_consumer", consumer
, 0, NULL
, NULL
);
435 if ( argc
> 1 && inigo
!= NULL
&& mlt_producer_get_length( inigo
) > 0 )
437 // Parse the arguments
438 for ( i
= 1; i
< argc
; i
++ )
440 if ( !strcmp( argv
[ i
], "-serialise" ) )
442 if ( store
!= stdout
)
448 fprintf( store
, "%s\n", argv
[ i
] );
452 while ( argv
[ i
] != NULL
&& argv
[ i
][ 0 ] != '-' )
455 fprintf( store
, "%s\n", argv
[ i
] );
463 if ( consumer
!= NULL
&& store
== NULL
)
465 // Get inigo's properties
466 mlt_properties inigo_props
= MLT_PRODUCER_PROPERTIES( inigo
);
468 // Get the last group
469 mlt_properties group
= mlt_properties_get_data( inigo_props
, "group", 0 );
471 // Apply group settings
472 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( consumer
);
473 mlt_properties_inherit( properties
, group
);
475 // Connect consumer to inigo
476 mlt_consumer_connect( consumer
, MLT_PRODUCER_SERVICE( inigo
) );
478 // Start the consumer
479 mlt_consumer_start( consumer
);
481 // Transport functionality
482 transport( inigo
, consumer
);
485 mlt_consumer_stop( consumer
);
487 else if ( store
!= NULL
&& store
!= stdout
&& name
!= NULL
)
489 fprintf( stderr
, "Project saved as %s.\n", name
);
495 fprintf( stderr
, "Usage: inigo [ -profile name ]\n"
496 " [ -query [ consumers | filters | producers | transitions |\n"
497 " type=identifer ] ]\n"
498 " [ -serialise [ filename.inigo ] ]\n"
499 " [ -group [ name=value ]* ]\n"
500 " [ -consumer id[:arg] [ name=value ]* [ silent=1 ] [ progress=1 ] ]\n"
501 " [ -filter filter[:arg] [ name=value ]* ]\n"
502 " [ -attach filter[:arg] [ name=value ]* ]\n"
503 " [ -mix length [ -mixer transition ]* ]\n"
504 " [ -transition id[:arg] [ name=value ]* ]\n"
505 " [ -blank frames ]\n"
507 " [ -split relative-frame ]\n"
509 " [ -repeat times ]\n"
510 " [ producer [ name=value ]* ]+\n" );
513 // Close the consumer
514 if ( consumer
!= NULL
)
515 mlt_consumer_close( consumer
);
517 // Close the producer
519 mlt_producer_close( inigo
);
522 mlt_profile_close( profile
);
526 mlt_factory_close( );