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( char *id
, mlt_producer producer
)
161 char *arg
= id
!= NULL ?
strchr( id
, ':' ) : NULL
;
164 mlt_consumer consumer
= mlt_factory_consumer( 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
);
169 mlt_properties_set_data( properties
, "transport_producer", producer
, 0, NULL
, NULL
);
170 mlt_properties_set_data( MLT_PRODUCER_PROPERTIES( producer
), "transport_consumer", consumer
, 0, NULL
, NULL
);
177 static void event_handling( mlt_producer producer
, mlt_consumer consumer
)
181 while ( SDL_PollEvent( &event
) )
186 mlt_properties_set_int( MLT_PRODUCER_PROPERTIES( consumer
), "done", 1 );
190 if ( event
.key
.keysym
.unicode
< 0x80 && event
.key
.keysym
.unicode
> 0 )
192 char keyboard
[ 2 ] = { event
.key
.keysym
.unicode
, 0 };
193 transport_action( producer
, keyboard
);
202 static void transport( mlt_producer producer
, mlt_consumer consumer
)
204 mlt_properties properties
= MLT_PRODUCER_PROPERTIES( producer
);
205 int silent
= mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer
), "silent" );
206 struct timespec tm
= { 0, 40000 };
208 if ( mlt_properties_get_int( properties
, "done" ) == 0 && !mlt_consumer_is_stopped( consumer
) )
214 fprintf( stderr
, "+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+\n" );
215 fprintf( stderr
, "|1=-10| |2= -5| |3= -2| |4= -1| |5= 0| |6= 1| |7= 2| |8= 5| |9= 10|\n" );
216 fprintf( stderr
, "+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+\n" );
218 fprintf( stderr
, "+---------------------------------------------------------------------+\n" );
219 fprintf( stderr
, "| H = back 1 minute, L = forward 1 minute |\n" );
220 fprintf( stderr
, "| h = previous frame, l = next frame |\n" );
221 fprintf( stderr
, "| g = start of clip, j = next clip, k = previous clip |\n" );
222 fprintf( stderr
, "| 0 = restart, q = quit, space = play |\n" );
223 fprintf( stderr
, "+---------------------------------------------------------------------+\n" );
226 while( mlt_properties_get_int( properties
, "done" ) == 0 && !mlt_consumer_is_stopped( consumer
) )
228 int value
= silent ?
-1 : term_read( );
232 char string
[ 2 ] = { value
, 0 };
233 transport_action( producer
, string
);
237 event_handling( producer
, consumer
);
240 if ( !silent
&& mlt_properties_get_int( properties
, "stats_off" ) == 0 )
241 fprintf( stderr
, "Current Position: %10d\r", (int)mlt_producer_position( producer
) );
244 nanosleep( &tm
, NULL
);
248 fprintf( stderr
, "\n" );
252 int main( int argc
, char **argv
)
255 mlt_consumer consumer
= NULL
;
256 mlt_producer inigo
= NULL
;
259 struct sched_param scp
;
261 // Use realtime scheduling if possible
262 memset( &scp
, '\0', sizeof( scp
) );
263 scp
.sched_priority
= sched_get_priority_max( SCHED_FIFO
) - 1;
265 sched_setscheduler( 0, SCHED_FIFO
, &scp
);
268 // Construct the factory
269 mlt_factory_init( NULL
);
271 // Check for serialisation switch first
272 for ( i
= 1; i
< argc
; i
++ )
274 if ( !strcmp( argv
[ i
], "-serialise" ) )
277 if ( strstr( name
, ".inigo" ) )
278 store
= fopen( name
, "w" );
282 // Get inigo producer
284 inigo
= mlt_factory_producer( "inigo", &argv
[ 1 ] );
286 if ( argc
> 1 && inigo
!= NULL
&& mlt_producer_get_length( inigo
) > 0 )
288 // Get inigo's properties
289 mlt_properties inigo_props
= MLT_PRODUCER_PROPERTIES( inigo
);
291 // Get the last group
292 mlt_properties group
= mlt_properties_get_data( inigo_props
, "group", 0 );
294 // Parse the arguments
295 for ( i
= 1; i
< argc
; i
++ )
297 if ( !strcmp( argv
[ i
], "-consumer" ) )
299 consumer
= create_consumer( argv
[ ++ i
], inigo
);
300 while ( argv
[ i
+ 1 ] != NULL
&& strstr( argv
[ i
+ 1 ], "=" ) )
301 mlt_properties_parse( group
, argv
[ ++ i
] );
303 else if ( !strcmp( argv
[ i
], "-serialise" ) )
310 fprintf( store
, "%s\n", argv
[ i
] );
314 while ( argv
[ i
] != NULL
&& argv
[ i
][ 0 ] != '-' )
317 fprintf( store
, "%s\n", argv
[ i
] );
325 // If we have no consumer, default to sdl
326 if ( store
== NULL
&& consumer
== NULL
)
327 consumer
= create_consumer( NULL
, inigo
);
329 if ( consumer
!= NULL
&& store
== NULL
)
331 // Apply group settings
332 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( consumer
);
333 mlt_properties_inherit( properties
, group
);
335 // Connect consumer to inigo
336 mlt_consumer_connect( consumer
, MLT_PRODUCER_SERVICE( inigo
) );
338 // Start the consumer
339 mlt_consumer_start( consumer
);
341 // Transport functionality
342 transport( inigo
, consumer
);
345 mlt_consumer_stop( consumer
);
347 else if ( store
!= NULL
)
349 fprintf( stderr
, "Project saved as %s.\n", name
);
355 fprintf( stderr
, "Usage: inigo [ -group [ name=value ]* ]\n"
356 " [ -consumer id[:arg] [ name=value ]* ]\n"
357 " [ -filter filter[:arg] [ name=value ] * ]\n"
358 " [ -attach filter[:arg] [ name=value ] * ]\n"
359 " [ -mix length [ -mixer transition ]* ]\n"
360 " [ -transition id[:arg] [ name=value ] * ]\n"
361 " [ -blank frames ]\n"
363 " [ -split relative-frame ]\n"
365 " [ -repeat times ]\n"
366 " [ producer [ name=value ] * ]+\n" );
369 // Close the consumer
370 if ( consumer
!= NULL
)
371 mlt_consumer_close( consumer
);
373 // Close the producer
375 mlt_producer_close( inigo
);
378 mlt_factory_close( );