X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Finigo%2Fproducer_inigo.c;h=2a46fed02730db9ec8e8a1e3f31785bef60964d3;hb=702e73b84d90830062ebe07ba01b72ad59d48d93;hp=8e1b1c81194d149fa73a8c9c065d25a6827cb70f;hpb=7803706d8a1172d0dd03248da73efe5aada98255;p=melted diff --git a/src/modules/inigo/producer_inigo.c b/src/modules/inigo/producer_inigo.c index 8e1b1c8..2a46fed 100644 --- a/src/modules/inigo/producer_inigo.c +++ b/src/modules/inigo/producer_inigo.c @@ -47,7 +47,7 @@ mlt_producer producer_inigo_file_init( char *file ) if ( result != NULL ) { - mlt_properties properties = mlt_producer_properties( result ); + mlt_properties properties = MLT_PRODUCER_PROPERTIES( result ); mlt_properties_set( properties, "resource", file ); } @@ -77,17 +77,32 @@ static mlt_producer create_producer( mlt_field field, char *file ) return result; } +static mlt_filter create_attach( mlt_field field, char *id, int track ) +{ + char *temp = strdup( id ); + char *arg = strchr( temp, ':' ); + if ( arg != NULL ) + *arg ++ = '\0'; + mlt_filter filter = mlt_factory_filter( temp, arg ); + if ( filter != NULL ) + track_service( field, filter, ( mlt_destructor )mlt_filter_close ); + free( temp ); + return filter; +} + static mlt_filter create_filter( mlt_field field, char *id, int track ) { - char *arg = strchr( id, ':' ); + char *temp = strdup( id ); + char *arg = strchr( temp, ':' ); if ( arg != NULL ) *arg ++ = '\0'; - mlt_filter filter = mlt_factory_filter( id, arg ); + mlt_filter filter = mlt_factory_filter( temp, arg ); if ( filter != NULL ) { mlt_field_plant_filter( field, filter, track ); track_service( field, filter, ( mlt_destructor )mlt_filter_close ); } + free( temp ); return filter; } @@ -110,12 +125,15 @@ 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_properties properties = MLT_TRACTOR_PROPERTIES( tractor ); + 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 ); @@ -133,52 +151,247 @@ 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-track" ) || + !strcmp( argv[ i ], "-attach-clip" ) ) + { + int type = !strcmp( argv[ i ], "-attach" ) ? 0 : + !strcmp( argv[ i ], "-attach-cut" ) ? 1 : + !strcmp( argv[ i ], "-attach-track" ) ? 2 : 3; + 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 )playlist, filter ); + else if ( type == 3 ) + mlt_service_attach( ( mlt_service )mlt_producer_cut_parent( producer ), filter ); + + properties = MLT_FILTER_PROPERTIES( filter ); + mlt_properties_inherit( properties, group ); + } + else if ( filter != NULL ) + { + mlt_service_attach( ( mlt_service )playlist, 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 ); if ( filter != NULL ) { - properties = mlt_filter_properties( filter ); + properties = MLT_FILTER_PROPERTIES( filter ); mlt_properties_inherit( properties, group ); } } 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 ); + properties = MLT_TRANSITION_PROPERTIES( transition ); mlt_properties_inherit( properties, group ); } } 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 ], "-null-track" ) || + !strcmp( argv[ i ], "-video-track" ) || + !strcmp( argv[ i ], "-audio-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 ( mlt_producer_get_playtime( MLT_PLAYLIST_PRODUCER( playlist ) ) > 0 ) + { + 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 ], "-null-track" ) || !strcmp( argv[ i ], "-hide-track" ) ) + mlt_properties_set_int( properties, "hide", 3 ); + else if ( !strcmp( argv[ i ], "-audio-track" ) || !strcmp( argv[ i ], "-hide-video" ) ) + mlt_properties_set_int( properties, "hide", 1 ); + else if ( !strcmp( argv[ i ], "-video-track" ) || !strcmp( argv[ i ], "-hide-audio" ) ) + mlt_properties_set_int( properties, "hide", 2 ); + } } - else if ( strchr( argv[ i ], '=' ) ) + else if ( strchr( argv[ i ], '=' ) && strstr( argv[ i ], " 0 ) - mlt_multitrack_connect( multitrack, mlt_playlist_producer( playlist ), track ); + mlt_multitrack_connect( multitrack, MLT_PLAYLIST_PRODUCER( playlist ), track ); - mlt_tractor tractor = mlt_field_tractor( field ); - mlt_producer prod = mlt_tractor_producer( tractor ); - mlt_properties props = mlt_tractor_properties( tractor ); - mlt_properties_set_data( props, "multitrack", multitrack, 0, ( mlt_destructor )mlt_multitrack_close, NULL ); - mlt_properties_set_data( props, "field", field, 0, ( mlt_destructor )mlt_field_close, 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 ) ) ); + 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_tractor_producer( tractor ); + return prod; }