X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Finigo%2Fproducer_inigo.c;h=80aee87c5d3a2f07e41c94324fc294b6e0a231ff;hb=3e00d7e35326b6fecbd95f459266f91fc60e6f15;hp=a3dbc10662030f8ee93fee0ca4afdd89fb07d8b3;hpb=cc8b6005abe30b5f0816b5aa6b87aa6867275228;p=melted diff --git a/src/modules/inigo/producer_inigo.c b/src/modules/inigo/producer_inigo.c index a3dbc10..80aee87 100644 --- a/src/modules/inigo/producer_inigo.c +++ b/src/modules/inigo/producer_inigo.c @@ -26,7 +26,7 @@ #include -static mlt_producer parse_inigo( char *file ) +mlt_producer producer_inigo_file_init( char *file ) { FILE *input = fopen( file, "r" ); char **args = calloc( sizeof( char * ), 1000 ); @@ -44,12 +44,11 @@ static mlt_producer parse_inigo( char *file ) } mlt_producer result = producer_inigo_init( args ); + if ( result != NULL ) { mlt_properties properties = mlt_producer_properties( result ); - mlt_field field = mlt_properties_get_data( properties, "field", NULL ); mlt_properties_set( properties, "resource", file ); - mlt_properties_set( mlt_field_properties( field ), "resource", file ); } while( count -- ) @@ -59,45 +58,6 @@ static mlt_producer parse_inigo( char *file ) return result; } -static mlt_producer create_producer( char *file ) -{ - mlt_producer result = NULL; - - // 1st Line preferences - if ( strstr( file, ".inigo" ) ) - result = parse_inigo( file ); - else if ( strstr( file, ".mpg" ) ) - result = mlt_factory_producer( "mcmpeg", file ); - else if ( strstr( file, ".mpeg" ) ) - result = mlt_factory_producer( "mcmpeg", file ); - else if ( strstr( file, ".dv" ) ) - result = mlt_factory_producer( "mcdv", file ); - else if ( strstr( file, ".dif" ) ) - result = mlt_factory_producer( "mcdv", file ); - else if ( strstr( file, ".jpg" ) ) - result = mlt_factory_producer( "pixbuf", file ); - else if ( strstr( file, ".JPG" ) ) - result = mlt_factory_producer( "pixbuf", file ); - else if ( strstr( file, ".jpeg" ) ) - result = mlt_factory_producer( "pixbuf", file ); - else if ( strstr( file, ".png" ) ) - result = mlt_factory_producer( "pixbuf", file ); - else if ( strstr( file, ".txt" ) ) - result = mlt_factory_producer( "pango", file ); - - // 2nd Line fallbacks - if ( result == NULL && strstr( file, ".dv" ) ) - result = mlt_factory_producer( "libdv", file ); - else if ( result == NULL && strstr( file, ".dif" ) ) - result = mlt_factory_producer( "libdv", file ); - - // 3rd line fallbacks - if ( result == NULL ) - result = mlt_factory_producer( "ffmpeg", file ); - - return result; -} - static void track_service( mlt_field field, void *service, mlt_destructor destructor ) { mlt_properties properties = mlt_field_properties( field ); @@ -107,6 +67,27 @@ static void track_service( mlt_field field, void *service, mlt_destructor destru mlt_properties_set_int( properties, "registered", ++ registered ); } +static mlt_producer create_producer( mlt_field field, char *file ) +{ + mlt_producer result = mlt_factory_producer( "fezzik", file ); + + if ( result != NULL ) + track_service( field, result, ( mlt_destructor )mlt_producer_close ); + + return result; +} + +static mlt_filter create_attach( mlt_field field, char *id, int track ) +{ + char *arg = strchr( id, ':' ); + if ( arg != NULL ) + *arg ++ = '\0'; + mlt_filter filter = mlt_factory_filter( id, arg ); + if ( filter != NULL ) + track_service( field, filter, ( mlt_destructor )mlt_filter_close ); + return filter; +} + static mlt_filter create_filter( mlt_field field, char *id, int track ) { char *arg = strchr( id, ':' ); @@ -135,22 +116,20 @@ static mlt_transition create_transition( mlt_field field, char *id, int track ) return transition; } -static void set_properties( mlt_properties properties, char *namevalue ) -{ - mlt_properties_parse( properties, namevalue ); -} - mlt_producer producer_inigo_init( char **argv ) { int i; int track = 0; mlt_producer producer = NULL; + mlt_tractor mix = NULL; mlt_playlist playlist = mlt_playlist_init( ); mlt_properties group = mlt_properties_new( ); mlt_properties properties = group; - mlt_field field = mlt_field_init( ); + mlt_tractor tractor = mlt_tractor_new( ); + mlt_field field = mlt_tractor_field( tractor ); mlt_properties field_properties = mlt_field_properties( field ); - mlt_multitrack multitrack = mlt_field_multitrack( field ); + mlt_multitrack multitrack = mlt_tractor_multitrack( tractor ); + char *title = NULL; // We need to track the number of registered filters mlt_properties_set_int( field_properties, "registered", 0 ); @@ -158,11 +137,7 @@ mlt_producer producer_inigo_init( char **argv ) // Parse the arguments for ( i = 0; argv[ i ] != NULL; i ++ ) { - if ( !strcmp( argv[ i ], "-serialise" ) ) - { - i ++; - } - else if ( !strcmp( argv[ i ], "-group" ) ) + if ( !strcmp( argv[ i ], "-group" ) ) { if ( mlt_properties_count( group ) != 0 ) { @@ -172,6 +147,171 @@ mlt_producer producer_inigo_init( char **argv ) if ( group != NULL ) properties = group; } + else if ( !strcmp( argv[ i ], "-attach" ) || + !strcmp( argv[ i ], "-attach-cut" ) || + !strcmp( argv[ i ], "-attach-clip" ) ) + { + int type = !strcmp( argv[ i ], "-attach" ) ? 0 : + !strcmp( argv[ i ], "-attach-cut" ) ? 1 : + 2; + mlt_filter filter = create_attach( field, argv[ ++ i ], track ); + if ( producer != NULL && !mlt_producer_is_cut( producer ) ) + { + mlt_playlist_clip_info info; + mlt_playlist_append( playlist, producer ); + mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 ); + producer = info.cut; + } + + if ( type == 1 || type == 2 ) + { + mlt_playlist_clip_info info; + mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 ); + producer = info.cut; + } + + if ( filter != NULL && mlt_playlist_count( playlist ) > 0 ) + { + if ( type == 0 ) + mlt_service_attach( ( mlt_service )properties, filter ); + else if ( type == 1 ) + mlt_service_attach( ( mlt_service )producer, filter ); + else if ( type == 2 ) + mlt_service_attach( ( mlt_service )mlt_producer_cut_parent( producer ), filter ); + + properties = mlt_filter_properties( filter ); + mlt_properties_inherit( properties, group ); + } + } + else if ( !strcmp( argv[ i ], "-repeat" ) ) + { + int repeat = atoi( argv[ ++ i ] ); + if ( producer != NULL && !mlt_producer_is_cut( producer ) ) + mlt_playlist_append( playlist, producer ); + producer = NULL; + if ( mlt_playlist_count( playlist ) > 0 ) + { + mlt_playlist_clip_info info; + mlt_playlist_repeat_clip( playlist, mlt_playlist_count( playlist ) - 1, repeat ); + mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 ); + producer = info.cut; + properties = mlt_producer_properties( producer ); + } + } + else if ( !strcmp( argv[ i ], "-split" ) ) + { + int split = atoi( argv[ ++ i ] ); + if ( producer != NULL && !mlt_producer_is_cut( producer ) ) + mlt_playlist_append( playlist, producer ); + producer = NULL; + if ( mlt_playlist_count( playlist ) > 0 ) + { + mlt_playlist_clip_info info; + mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 ); + split = split < 0 ? info.frame_out + split : split; + mlt_playlist_split( playlist, mlt_playlist_count( playlist ) - 1, split ); + mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 ); + producer = info.cut; + properties = mlt_producer_properties( producer ); + } + } + else if ( !strcmp( argv[ i ], "-swap" ) ) + { + if ( producer != NULL && !mlt_producer_is_cut( producer ) ) + mlt_playlist_append( playlist, producer ); + producer = NULL; + if ( mlt_playlist_count( playlist ) >= 2 ) + { + mlt_playlist_clip_info info; + mlt_playlist_move( playlist, mlt_playlist_count( playlist ) - 2, mlt_playlist_count( playlist ) - 1 ); + mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 ); + producer = info.cut; + properties = mlt_producer_properties( producer ); + } + } + else if ( !strcmp( argv[ i ], "-join" ) ) + { + int clips = atoi( argv[ ++ i ] ); + if ( producer != NULL && !mlt_producer_is_cut( producer ) ) + mlt_playlist_append( playlist, producer ); + producer = NULL; + if ( mlt_playlist_count( playlist ) > 0 ) + { + mlt_playlist_clip_info info; + mlt_playlist_join( playlist, mlt_playlist_count( playlist ) - clips - 1, clips, 0 ); + mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 ); + producer = info.cut; + properties = mlt_producer_properties( producer ); + } + } + else if ( !strcmp( argv[ i ], "-remove" ) ) + { + if ( producer != NULL && !mlt_producer_is_cut( producer ) ) + mlt_playlist_append( playlist, producer ); + producer = NULL; + if ( mlt_playlist_count( playlist ) > 0 ) + { + mlt_playlist_clip_info info; + mlt_playlist_remove( playlist, mlt_playlist_count( playlist ) - 1 ); + mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 ); + producer = info.cut; + properties = mlt_producer_properties( producer ); + } + } + else if ( !strcmp( argv[ i ], "-mix" ) ) + { + int length = atoi( argv[ ++ i ] ); + if ( producer != NULL && !mlt_producer_is_cut( producer ) ) + mlt_playlist_append( playlist, producer ); + producer = NULL; + if ( mlt_playlist_count( playlist ) >= 2 ) + { + if ( mlt_playlist_mix( playlist, mlt_playlist_count( playlist ) - 2, length, NULL ) == 0 ) + { + mlt_playlist_clip_info info; + mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 ); + if ( mlt_properties_get_data( ( mlt_properties )info.producer, "mlt_mix", NULL ) == NULL ) + mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 2 ); + mix = ( mlt_tractor )mlt_properties_get_data( ( mlt_properties )info.producer, "mlt_mix", NULL ); + properties = NULL; + } + else + { + fprintf( stderr, "Mix failed?\n" ); + } + } + else + { + fprintf( stderr, "Invalid position for a mix...\n" ); + } + } + else if ( !strcmp( argv[ i ], "-mixer" ) ) + { + if ( mix != NULL ) + { + char *id = strdup( argv[ ++ i ] ); + char *arg = strchr( id, ':' ); + mlt_field field = mlt_tractor_field( mix ); + mlt_transition transition = NULL; + if ( arg != NULL ) + *arg ++ = '\0'; + transition = mlt_factory_transition( id, arg ); + if ( transition != NULL ) + { + properties = mlt_transition_properties( transition ); + mlt_properties_inherit( properties, group ); + mlt_field_plant_transition( field, transition, 0, 1 ); + mlt_properties_set_position( properties, "in", 0 ); + mlt_properties_set_position( properties, "out", mlt_producer_get_out( ( mlt_producer )mix ) ); + mlt_transition_close( transition ); + } + free( id ); + } + else + { + fprintf( stderr, "Invalid mixer...\n" ); + } + } else if ( !strcmp( argv[ i ], "-filter" ) ) { mlt_filter filter = create_filter( field, argv[ ++ i ], track ); @@ -183,7 +323,7 @@ mlt_producer producer_inigo_init( char **argv ) } else if ( !strcmp( argv[ i ], "-transition" ) ) { - mlt_transition transition = create_transition( field, argv[ ++ i ], track ); + mlt_transition transition = create_transition( field, argv[ ++ i ], track - 1 ); if ( transition != NULL ) { properties = mlt_transition_properties( transition ); @@ -192,28 +332,44 @@ mlt_producer producer_inigo_init( char **argv ) } else if ( !strcmp( argv[ i ], "-blank" ) ) { - if ( producer != NULL ) + if ( producer != NULL && !mlt_producer_is_cut( producer ) ) mlt_playlist_append( playlist, producer ); producer = NULL; mlt_playlist_blank( playlist, atof( argv[ ++ i ] ) ); } - else if ( !strcmp( argv[ i ], "-track" ) ) + else if ( !strcmp( argv[ i ], "-track" ) || + !strcmp( argv[ i ], "-hide-track" ) || + !strcmp( argv[ i ], "-hide-video" ) || + !strcmp( argv[ i ], "-hide-audio" ) ) { - if ( producer != NULL ) + if ( producer != NULL && !mlt_producer_is_cut( producer ) ) mlt_playlist_append( playlist, producer ); producer = NULL; mlt_multitrack_connect( multitrack, mlt_playlist_producer( playlist ), track ++ ); + track_service( field, playlist, ( mlt_destructor )mlt_playlist_close ); playlist = mlt_playlist_init( ); + if ( playlist != NULL ) + { + properties = mlt_playlist_properties( playlist ); + if ( !strcmp( argv[ i ], "-hide-track" ) ) + mlt_properties_set_int( properties, "hide", 3 ); + else if ( !strcmp( argv[ i ], "-hide-video" ) ) + mlt_properties_set_int( properties, "hide", 1 ); + else if ( !strcmp( argv[ i ], "-hide-audio" ) ) + mlt_properties_set_int( properties, "hide", 2 ); + } } - else if ( strstr( argv[ i ], "=" ) ) + else if ( strchr( argv[ i ], '=' ) ) { - set_properties( properties, argv[ i ] ); + mlt_properties_parse( properties, argv[ i ] ); } else if ( argv[ i ][ 0 ] != '-' ) { - if ( producer != NULL ) + if ( producer != NULL && !mlt_producer_is_cut( producer ) ) mlt_playlist_append( playlist, producer ); - producer = create_producer( argv[ i ] ); + if ( title == NULL ) + title = argv[ i ]; + producer = create_producer( field, argv[ i ] ); if ( producer != NULL ) { properties = mlt_producer_properties( producer ); @@ -222,27 +378,38 @@ mlt_producer producer_inigo_init( char **argv ) } else { - while ( argv[ i ] != NULL && argv[ i ][ 0 ] != '-' ) + if ( !strcmp( argv[ i ], "-serialise" ) ) + i += 2; + else if ( !strcmp( argv[ i ], "-consumer" ) ) + i += 2; + + while ( argv[ i ] != NULL && strchr( argv[ i ], '=' ) ) i ++; + i --; } } - // Connect producer to playlist - if ( producer != NULL ) + // Connect last producer to playlist + if ( producer != NULL && !mlt_producer_is_cut( producer ) ) mlt_playlist_append( playlist, producer ); - // We must have a producer at this point + // Track the last playlist too + track_service( field, playlist, ( mlt_destructor )mlt_playlist_close ); + + // We must have a playlist to connect if ( mlt_playlist_count( playlist ) > 0 ) - { - // Connect multitrack to producer mlt_multitrack_connect( multitrack, mlt_playlist_producer( playlist ), track ); - } - mlt_properties props = mlt_multitrack_properties( multitrack ); - mlt_properties_set_data( props, "field", field, 0, NULL, NULL ); - mlt_properties_set_data( props, "group", group, 0, NULL, NULL ); + mlt_producer prod = mlt_tractor_producer( tractor ); + mlt_producer_optimise( prod ); + mlt_properties props = mlt_tractor_properties( tractor ); + mlt_properties_set_data( props, "group", group, 0, ( mlt_destructor )mlt_properties_close, NULL ); + mlt_properties_set_position( props, "length", mlt_producer_get_out( mlt_multitrack_producer( multitrack ) ) + 1 ); + mlt_producer_set_in_and_out( prod, 0, mlt_producer_get_out( mlt_multitrack_producer( multitrack ) ) ); + mlt_properties_set_double( props, "fps", mlt_producer_get_fps( mlt_multitrack_producer( multitrack ) ) ); + if ( title != NULL ) + mlt_properties_set( props, "title", strchr( title, '/' ) ? strrchr( title, '/' ) + 1 : title ); - return mlt_multitrack_producer( multitrack ); + return prod; } -