6 #include <framework/mlt.h>
10 static void transport_action( mlt_producer producer
, char *value
)
12 mlt_properties properties
= MLT_PRODUCER_PROPERTIES( producer
);
13 mlt_multitrack multitrack
= mlt_properties_get_data( properties
, "multitrack", NULL
);
14 mlt_consumer consumer
= mlt_properties_get_data( properties
, "transport_consumer", NULL
);
16 mlt_properties_set_int( properties
, "stats_off", 0 );
18 if ( strlen( value
) == 1 )
23 mlt_properties_set_int( properties
, "done", 1 );
26 mlt_producer_set_speed( producer
, 1 );
27 mlt_producer_seek( producer
, 0 );
30 mlt_producer_set_speed( producer
, -10 );
33 mlt_producer_set_speed( producer
, -5 );
36 mlt_producer_set_speed( producer
, -2 );
39 mlt_producer_set_speed( producer
, -1 );
42 mlt_producer_set_speed( producer
, 0 );
46 mlt_producer_set_speed( producer
, 1 );
49 mlt_producer_set_speed( producer
, 2 );
52 mlt_producer_set_speed( producer
, 5 );
55 mlt_producer_set_speed( producer
, 10 );
58 if ( multitrack
!= NULL
)
61 mlt_position last
= -1;
62 fprintf( stderr
, "\n" );
63 for ( i
= 0; 1; i
++ )
65 mlt_position time
= mlt_multitrack_clip( multitrack
, mlt_whence_relative_start
, i
);
69 fprintf( stderr
, "%d: %d\n", i
, time
);
75 if ( multitrack
!= NULL
)
77 mlt_position time
= mlt_multitrack_clip( multitrack
, mlt_whence_relative_current
, 0 );
78 mlt_producer_seek( producer
, time
);
82 if ( producer
!= NULL
)
84 mlt_position position
= mlt_producer_position( producer
);
85 mlt_producer_seek( producer
, position
- ( mlt_producer_get_fps( producer
) * 60 ) );
89 if ( producer
!= NULL
)
91 mlt_position position
= mlt_producer_position( producer
);
92 mlt_producer_set_speed( producer
, 0 );
93 mlt_producer_seek( producer
, position
- 1 );
97 if ( multitrack
!= NULL
)
99 mlt_position time
= mlt_multitrack_clip( multitrack
, mlt_whence_relative_current
, 1 );
100 mlt_producer_seek( producer
, time
);
104 if ( multitrack
!= NULL
)
106 mlt_position time
= mlt_multitrack_clip( multitrack
, mlt_whence_relative_current
, -1 );
107 mlt_producer_seek( producer
, time
);
111 if ( producer
!= NULL
)
113 mlt_position position
= mlt_producer_position( producer
);
114 if ( mlt_producer_get_speed( producer
) != 0 )
115 mlt_producer_set_speed( producer
, 0 );
117 mlt_producer_seek( producer
, position
+ 1 );
121 if ( producer
!= NULL
)
123 mlt_position position
= mlt_producer_position( producer
);
124 mlt_producer_seek( producer
, position
+ ( mlt_producer_get_fps( producer
) * 60 ) );
129 mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( consumer
), "refresh", 1 );
132 mlt_properties_set_int( properties
, "stats_off", 0 );
135 static mlt_consumer
create_consumer( char *id
, mlt_producer producer
)
137 char *arg
= id
!= NULL ?
strchr( id
, ':' ) : NULL
;
140 mlt_consumer consumer
= mlt_factory_consumer( id
, arg
);
141 if ( consumer
!= NULL
)
143 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( consumer
);
144 mlt_properties_set_data( properties
, "transport_callback", transport_action
, 0, NULL
, NULL
);
145 mlt_properties_set_data( properties
, "transport_producer", producer
, 0, NULL
, NULL
);
146 mlt_properties_set_data( MLT_PRODUCER_PROPERTIES( producer
), "transport_consumer", consumer
, 0, NULL
, NULL
);
151 static void transport( mlt_producer producer
, mlt_consumer consumer
)
153 mlt_properties properties
= MLT_PRODUCER_PROPERTIES( producer
);
154 int silent
= mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer
), "silent" );
155 struct timespec tm
= { 0, 40000 };
157 if ( mlt_properties_get_int( properties
, "done" ) == 0 && !mlt_consumer_is_stopped( consumer
) )
163 fprintf( stderr
, "+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+\n" );
164 fprintf( stderr
, "|1=-10| |2= -5| |3= -2| |4= -1| |5= 0| |6= 1| |7= 2| |8= 5| |9= 10|\n" );
165 fprintf( stderr
, "+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+\n" );
167 fprintf( stderr
, "+---------------------------------------------------------------------+\n" );
168 fprintf( stderr
, "| H = back 1 minute, L = forward 1 minute |\n" );
169 fprintf( stderr
, "| h = previous frame, l = next frame |\n" );
170 fprintf( stderr
, "| g = start of clip, j = next clip, k = previous clip |\n" );
171 fprintf( stderr
, "| 0 = restart, q = quit, space = play |\n" );
172 fprintf( stderr
, "+---------------------------------------------------------------------+\n" );
175 while( mlt_properties_get_int( properties
, "done" ) == 0 && !mlt_consumer_is_stopped( consumer
) )
177 int value
= silent ?
-1 : term_read( );
180 transport_action( producer
, ( char * )&value
);
182 if ( !silent
&& mlt_properties_get_int( properties
, "stats_off" ) == 0 )
183 fprintf( stderr
, "Current Position: %10d\r", mlt_producer_position( producer
) );
186 nanosleep( &tm
, NULL
);
190 fprintf( stderr
, "\n" );
194 int main( int argc
, char **argv
)
197 mlt_consumer consumer
= NULL
;
198 mlt_producer inigo
= NULL
;
201 struct sched_param scp
;
203 // Use realtime scheduling if possible
204 memset( &scp
, '\0', sizeof( scp
) );
205 scp
.sched_priority
= sched_get_priority_max( SCHED_FIFO
) - 1;
207 sched_setscheduler( 0, SCHED_FIFO
, &scp
);
210 // Construct the factory
211 mlt_factory_init( NULL
);
213 // Check for serialisation switch first
214 for ( i
= 1; i
< argc
; i
++ )
216 if ( !strcmp( argv
[ i
], "-serialise" ) )
219 if ( strstr( name
, ".inigo" ) )
220 store
= fopen( name
, "w" );
224 // Get inigo producer
226 inigo
= mlt_factory_producer( "inigo", &argv
[ 1 ] );
228 if ( argc
> 1 && inigo
!= NULL
&& mlt_producer_get_length( inigo
) > 0 )
230 // Get inigo's properties
231 mlt_properties inigo_props
= MLT_PRODUCER_PROPERTIES( inigo
);
233 // Get the last group
234 mlt_properties group
= mlt_properties_get_data( inigo_props
, "group", 0 );
236 // Parse the arguments
237 for ( i
= 1; i
< argc
; i
++ )
239 if ( !strcmp( argv
[ i
], "-consumer" ) )
241 consumer
= create_consumer( argv
[ ++ i
], inigo
);
242 while ( argv
[ i
+ 1 ] != NULL
&& strstr( argv
[ i
+ 1 ], "=" ) )
243 mlt_properties_parse( group
, argv
[ ++ i
] );
245 else if ( !strcmp( argv
[ i
], "-serialise" ) )
252 fprintf( store
, "%s\n", argv
[ i
] );
256 while ( argv
[ i
] != NULL
&& argv
[ i
][ 0 ] != '-' )
259 fprintf( store
, "%s\n", argv
[ i
] );
267 // If we have no consumer, default to sdl
268 if ( store
== NULL
&& consumer
== NULL
)
269 consumer
= create_consumer( NULL
, inigo
);
271 if ( consumer
!= NULL
&& store
== NULL
)
273 // Apply group settings
274 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( consumer
);
275 mlt_properties_inherit( properties
, group
);
277 // Connect consumer to inigo
278 mlt_consumer_connect( consumer
, MLT_PRODUCER_SERVICE( inigo
) );
280 // Start the consumer
281 mlt_consumer_start( consumer
);
283 // Transport functionality
284 transport( inigo
, consumer
);
287 mlt_consumer_stop( consumer
);
289 else if ( store
!= NULL
)
291 fprintf( stderr
, "Project saved as %s.\n", name
);
297 fprintf( stderr
, "Usage: inigo [ -group [ name=value ]* ]\n"
298 " [ -consumer id[:arg] [ name=value ]* ]\n"
299 " [ -filter filter[:arg] [ name=value ] * ]\n"
300 " [ -attach filter[:arg] [ name=value ] * ]\n"
301 " [ -mix length [ -mixer transition ]* ]\n"
302 " [ -transition id[:arg] [ name=value ] * ]\n"
303 " [ -blank frames ]\n"
305 " [ -split relative-frame ]\n"
307 " [ -repeat times ]\n"
308 " [ producer [ name=value ] * ]+\n" );
311 // Close the consumer
312 if ( consumer
!= NULL
)
313 mlt_consumer_close( consumer
);
315 // Close the producer
317 mlt_producer_close( inigo
);
320 mlt_factory_close( );