2 * producer_inigo.c -- simple inigo test case
3 * Copyright (C) 2003-2004 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.
21 #include "producer_inigo.h"
27 #include <framework/mlt.h>
29 mlt_producer
producer_inigo_file_init( char *file
)
31 FILE *input
= fopen( file
, "r" );
32 char **args
= calloc( sizeof( char * ), 1000 );
38 while( fgets( temp
, 2048, input
) )
40 temp
[ strlen( temp
) - 1 ] = '\0';
41 if ( strcmp( temp
, "" ) )
42 args
[ count
++ ] = strdup( temp
);
46 mlt_producer result
= producer_inigo_init( args
);
50 mlt_properties properties
= MLT_PRODUCER_PROPERTIES( result
);
51 mlt_properties_set( properties
, "resource", file
);
55 free( args
[ count
] );
61 static void track_service( mlt_field field
, void *service
, mlt_destructor destructor
)
63 mlt_properties properties
= mlt_field_properties( field
);
64 int registered
= mlt_properties_get_int( properties
, "registered" );
65 char *key
= mlt_properties_get( properties
, "registered" );
66 mlt_properties_set_data( properties
, key
, service
, 0, destructor
, NULL
);
67 mlt_properties_set_int( properties
, "registered", ++ registered
);
70 static mlt_producer
create_producer( mlt_field field
, char *file
)
72 mlt_producer result
= mlt_factory_producer( "fezzik", file
);
75 track_service( field
, result
, ( mlt_destructor
)mlt_producer_close
);
80 static mlt_filter
create_attach( mlt_field field
, char *id
, int track
)
82 char *temp
= strdup( id
);
83 char *arg
= strchr( temp
, ':' );
86 mlt_filter filter
= mlt_factory_filter( temp
, arg
);
88 track_service( field
, filter
, ( mlt_destructor
)mlt_filter_close
);
93 static mlt_filter
create_filter( mlt_field field
, char *id
, int track
)
95 char *temp
= strdup( id
);
96 char *arg
= strchr( temp
, ':' );
99 mlt_filter filter
= mlt_factory_filter( temp
, arg
);
100 if ( filter
!= NULL
)
102 mlt_field_plant_filter( field
, filter
, track
);
103 track_service( field
, filter
, ( mlt_destructor
)mlt_filter_close
);
109 static mlt_transition
create_transition( mlt_field field
, char *id
, int track
)
111 char *arg
= strchr( id
, ':' );
114 mlt_transition transition
= mlt_factory_transition( id
, arg
);
115 if ( transition
!= NULL
)
117 mlt_field_plant_transition( field
, transition
, track
, track
+ 1 );
118 track_service( field
, transition
, ( mlt_destructor
)mlt_transition_close
);
123 mlt_producer
producer_inigo_init( char **argv
)
127 mlt_producer producer
= NULL
;
128 mlt_tractor mix
= NULL
;
129 mlt_playlist playlist
= mlt_playlist_init( );
130 mlt_properties group
= mlt_properties_new( );
131 mlt_tractor tractor
= mlt_tractor_new( );
132 mlt_properties properties
= MLT_TRACTOR_PROPERTIES( tractor
);
133 mlt_field field
= mlt_tractor_field( tractor
);
134 mlt_properties field_properties
= mlt_field_properties( field
);
135 mlt_multitrack multitrack
= mlt_tractor_multitrack( tractor
);
138 // We need to track the number of registered filters
139 mlt_properties_set_int( field_properties
, "registered", 0 );
141 // Parse the arguments
142 for ( i
= 0; argv
[ i
] != NULL
; i
++ )
144 if ( !strcmp( argv
[ i
], "-group" ) )
146 if ( mlt_properties_count( group
) != 0 )
148 mlt_properties_close( group
);
149 group
= mlt_properties_new( );
154 else if ( !strcmp( argv
[ i
], "-attach" ) ||
155 !strcmp( argv
[ i
], "-attach-cut" ) ||
156 !strcmp( argv
[ i
], "-attach-track" ) ||
157 !strcmp( argv
[ i
], "-attach-clip" ) )
159 int type
= !strcmp( argv
[ i
], "-attach" ) ?
0 :
160 !strcmp( argv
[ i
], "-attach-cut" ) ?
1 :
161 !strcmp( argv
[ i
], "-attach-track" ) ?
2 : 3;
162 mlt_filter filter
= create_attach( field
, argv
[ ++ i
], track
);
163 if ( producer
!= NULL
&& !mlt_producer_is_cut( producer
) )
165 mlt_playlist_clip_info info
;
166 mlt_playlist_append( playlist
, producer
);
167 mlt_playlist_get_clip_info( playlist
, &info
, mlt_playlist_count( playlist
) - 1 );
171 if ( type
== 1 || type
== 2 )
173 mlt_playlist_clip_info info
;
174 mlt_playlist_get_clip_info( playlist
, &info
, mlt_playlist_count( playlist
) - 1 );
178 if ( filter
!= NULL
&& mlt_playlist_count( playlist
) > 0 )
181 mlt_service_attach( ( mlt_service
)properties
, filter
);
182 else if ( type
== 1 )
183 mlt_service_attach( ( mlt_service
)producer
, filter
);
184 else if ( type
== 2 )
185 mlt_service_attach( ( mlt_service
)playlist
, filter
);
186 else if ( type
== 3 )
187 mlt_service_attach( ( mlt_service
)mlt_producer_cut_parent( producer
), filter
);
189 properties
= MLT_FILTER_PROPERTIES( filter
);
190 mlt_properties_inherit( properties
, group
);
192 else if ( filter
!= NULL
)
194 mlt_service_attach( ( mlt_service
)playlist
, filter
);
195 properties
= MLT_FILTER_PROPERTIES( filter
);
196 mlt_properties_inherit( properties
, group
);
199 else if ( !strcmp( argv
[ i
], "-repeat" ) )
201 int repeat
= atoi( argv
[ ++ i
] );
202 if ( producer
!= NULL
&& !mlt_producer_is_cut( producer
) )
203 mlt_playlist_append( playlist
, producer
);
205 if ( mlt_playlist_count( playlist
) > 0 )
207 mlt_playlist_clip_info info
;
208 mlt_playlist_repeat_clip( playlist
, mlt_playlist_count( playlist
) - 1, repeat
);
209 mlt_playlist_get_clip_info( playlist
, &info
, mlt_playlist_count( playlist
) - 1 );
211 properties
= MLT_PRODUCER_PROPERTIES( producer
);
214 else if ( !strcmp( argv
[ i
], "-split" ) )
216 int split
= atoi( argv
[ ++ i
] );
217 if ( producer
!= NULL
&& !mlt_producer_is_cut( producer
) )
218 mlt_playlist_append( playlist
, producer
);
220 if ( mlt_playlist_count( playlist
) > 0 )
222 mlt_playlist_clip_info info
;
223 mlt_playlist_get_clip_info( playlist
, &info
, mlt_playlist_count( playlist
) - 1 );
224 split
= split
< 0 ? info
.frame_out
+ split
: split
;
225 mlt_playlist_split( playlist
, mlt_playlist_count( playlist
) - 1, split
);
226 mlt_playlist_get_clip_info( playlist
, &info
, mlt_playlist_count( playlist
) - 1 );
228 properties
= MLT_PRODUCER_PROPERTIES( producer
);
231 else if ( !strcmp( argv
[ i
], "-swap" ) )
233 if ( producer
!= NULL
&& !mlt_producer_is_cut( producer
) )
234 mlt_playlist_append( playlist
, producer
);
236 if ( mlt_playlist_count( playlist
) >= 2 )
238 mlt_playlist_clip_info info
;
239 mlt_playlist_move( playlist
, mlt_playlist_count( playlist
) - 2, mlt_playlist_count( playlist
) - 1 );
240 mlt_playlist_get_clip_info( playlist
, &info
, mlt_playlist_count( playlist
) - 1 );
242 properties
= MLT_PRODUCER_PROPERTIES( producer
);
245 else if ( !strcmp( argv
[ i
], "-join" ) )
247 int clips
= atoi( argv
[ ++ i
] );
248 if ( producer
!= NULL
&& !mlt_producer_is_cut( producer
) )
249 mlt_playlist_append( playlist
, producer
);
251 if ( mlt_playlist_count( playlist
) > 0 )
253 mlt_playlist_clip_info info
;
254 int clip
= clips
<= 0 ?
0 : mlt_playlist_count( playlist
) - clips
- 1;
255 if ( clip
< 0 ) clip
= 0;
256 if ( clip
>= mlt_playlist_count( playlist
) ) clip
= mlt_playlist_count( playlist
) - 2;
257 if ( clips
< 0 ) clips
= mlt_playlist_count( playlist
) - 1;
258 mlt_playlist_join( playlist
, clip
, clips
, 0 );
259 mlt_playlist_get_clip_info( playlist
, &info
, mlt_playlist_count( playlist
) - 1 );
261 properties
= MLT_PRODUCER_PROPERTIES( producer
);
264 else if ( !strcmp( argv
[ i
], "-remove" ) )
266 if ( producer
!= NULL
&& !mlt_producer_is_cut( producer
) )
267 mlt_playlist_append( playlist
, producer
);
269 if ( mlt_playlist_count( playlist
) > 0 )
271 mlt_playlist_clip_info info
;
272 mlt_playlist_remove( playlist
, mlt_playlist_count( playlist
) - 1 );
273 mlt_playlist_get_clip_info( playlist
, &info
, mlt_playlist_count( playlist
) - 1 );
275 properties
= MLT_PRODUCER_PROPERTIES( producer
);
278 else if ( !strcmp( argv
[ i
], "-mix" ) )
280 int length
= atoi( argv
[ ++ i
] );
281 if ( producer
!= NULL
&& !mlt_producer_is_cut( producer
) )
282 mlt_playlist_append( playlist
, producer
);
284 if ( mlt_playlist_count( playlist
) >= 2 )
286 if ( mlt_playlist_mix( playlist
, mlt_playlist_count( playlist
) - 2, length
, NULL
) == 0 )
288 mlt_playlist_clip_info info
;
289 mlt_playlist_get_clip_info( playlist
, &info
, mlt_playlist_count( playlist
) - 1 );
290 if ( mlt_properties_get_data( ( mlt_properties
)info
.producer
, "mlt_mix", NULL
) == NULL
)
291 mlt_playlist_get_clip_info( playlist
, &info
, mlt_playlist_count( playlist
) - 2 );
292 mix
= ( mlt_tractor
)mlt_properties_get_data( ( mlt_properties
)info
.producer
, "mlt_mix", NULL
);
297 fprintf( stderr
, "Mix failed?\n" );
302 fprintf( stderr
, "Invalid position for a mix...\n" );
305 else if ( !strcmp( argv
[ i
], "-mixer" ) )
309 char *id
= strdup( argv
[ ++ i
] );
310 char *arg
= strchr( id
, ':' );
311 mlt_field field
= mlt_tractor_field( mix
);
312 mlt_transition transition
= NULL
;
315 transition
= mlt_factory_transition( id
, arg
);
316 if ( transition
!= NULL
)
318 properties
= MLT_TRANSITION_PROPERTIES( transition
);
319 mlt_properties_inherit( properties
, group
);
320 mlt_field_plant_transition( field
, transition
, 0, 1 );
321 mlt_properties_set_position( properties
, "in", 0 );
322 mlt_properties_set_position( properties
, "out", mlt_producer_get_out( ( mlt_producer
)mix
) );
323 mlt_transition_close( transition
);
329 fprintf( stderr
, "Invalid mixer...\n" );
332 else if ( !strcmp( argv
[ i
], "-filter" ) )
334 mlt_filter filter
= create_filter( field
, argv
[ ++ i
], track
);
335 if ( filter
!= NULL
)
337 properties
= MLT_FILTER_PROPERTIES( filter
);
338 mlt_properties_inherit( properties
, group
);
341 else if ( !strcmp( argv
[ i
], "-transition" ) )
343 mlt_transition transition
= create_transition( field
, argv
[ ++ i
], track
- 1 );
344 if ( transition
!= NULL
)
346 properties
= MLT_TRANSITION_PROPERTIES( transition
);
347 mlt_properties_inherit( properties
, group
);
350 else if ( !strcmp( argv
[ i
], "-blank" ) )
352 if ( producer
!= NULL
&& !mlt_producer_is_cut( producer
) )
353 mlt_playlist_append( playlist
, producer
);
355 mlt_playlist_blank( playlist
, atof( argv
[ ++ i
] ) );
357 else if ( !strcmp( argv
[ i
], "-track" ) ||
358 !strcmp( argv
[ i
], "-null-track" ) ||
359 !strcmp( argv
[ i
], "-video-track" ) ||
360 !strcmp( argv
[ i
], "-audio-track" ) ||
361 !strcmp( argv
[ i
], "-hide-track" ) ||
362 !strcmp( argv
[ i
], "-hide-video" ) ||
363 !strcmp( argv
[ i
], "-hide-audio" ) )
365 if ( producer
!= NULL
&& !mlt_producer_is_cut( producer
) )
366 mlt_playlist_append( playlist
, producer
);
368 if ( mlt_producer_get_playtime( MLT_PLAYLIST_PRODUCER( playlist
) ) > 0 )
370 mlt_multitrack_connect( multitrack
, MLT_PLAYLIST_PRODUCER( playlist
), track
++ );
371 track_service( field
, playlist
, ( mlt_destructor
)mlt_playlist_close
);
372 playlist
= mlt_playlist_init( );
374 if ( playlist
!= NULL
)
376 properties
= MLT_PLAYLIST_PROPERTIES( playlist
);
377 if ( !strcmp( argv
[ i
], "-null-track" ) || !strcmp( argv
[ i
], "-hide-track" ) )
378 mlt_properties_set_int( properties
, "hide", 3 );
379 else if ( !strcmp( argv
[ i
], "-audio-track" ) || !strcmp( argv
[ i
], "-hide-video" ) )
380 mlt_properties_set_int( properties
, "hide", 1 );
381 else if ( !strcmp( argv
[ i
], "-video-track" ) || !strcmp( argv
[ i
], "-hide-audio" ) )
382 mlt_properties_set_int( properties
, "hide", 2 );
385 else if ( strchr( argv
[ i
], '=' ) && strstr( argv
[ i
], "<?xml" ) != argv
[ i
] )
387 mlt_properties_parse( properties
, argv
[ i
] );
389 else if ( argv
[ i
][ 0 ] != '-' )
391 if ( producer
!= NULL
&& !mlt_producer_is_cut( producer
) )
392 mlt_playlist_append( playlist
, producer
);
393 if ( title
== NULL
&& strstr( argv
[ i
], "<?xml" ) != argv
[ i
] )
395 producer
= create_producer( field
, argv
[ i
] );
396 if ( producer
!= NULL
)
398 properties
= MLT_PRODUCER_PROPERTIES( producer
);
399 mlt_properties_inherit( properties
, group
);
404 if ( !strcmp( argv
[ i
], "-serialise" ) )
406 else if ( !strcmp( argv
[ i
], "-consumer" ) )
409 while ( argv
[ i
] != NULL
&& strchr( argv
[ i
], '=' ) )
416 // Connect last producer to playlist
417 if ( producer
!= NULL
&& !mlt_producer_is_cut( producer
) )
418 mlt_playlist_append( playlist
, producer
);
420 // Track the last playlist too
421 track_service( field
, playlist
, ( mlt_destructor
)mlt_playlist_close
);
423 // We must have a playlist to connect
424 if ( mlt_playlist_count( playlist
) > 0 )
425 mlt_multitrack_connect( multitrack
, MLT_PLAYLIST_PRODUCER( playlist
), track
);
427 mlt_producer prod
= MLT_TRACTOR_PRODUCER( tractor
);
428 mlt_producer_optimise( prod
);
429 mlt_properties props
= MLT_TRACTOR_PROPERTIES( tractor
);
430 mlt_properties_set_data( props
, "group", group
, 0, ( mlt_destructor
)mlt_properties_close
, NULL
);
431 mlt_properties_set_position( props
, "length", mlt_producer_get_out( MLT_MULTITRACK_PRODUCER( multitrack
) ) + 1 );
432 mlt_producer_set_in_and_out( prod
, 0, mlt_producer_get_out( MLT_MULTITRACK_PRODUCER( multitrack
) ) );
433 mlt_properties_set_double( props
, "fps", mlt_producer_get_fps( MLT_MULTITRACK_PRODUCER( multitrack
) ) );
435 mlt_properties_set( props
, "title", strchr( title
, '/' ) ?
strrchr( title
, '/' ) + 1 : title
);