static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable ) { // Get the filter mlt_filter filter = mlt_frame_pop_service( frame ); // Get the properties mlt_properties properties = MLT_FILTER_PROPERTIES( filter ); // Get the image int error = 0; *format = mlt_image_rgb24a; // Only process if we have no error and a valid colour space if ( error == 0 ) { mlt_service_lock( MLT_FILTER_SERVICE( filter ) ); mlt_producer producer = mlt_properties_get_data( properties, "producer", NULL ); mlt_transition transition = mlt_properties_get_data( properties, "transition", NULL ); mlt_frame a_frame = NULL; mlt_profile profile = mlt_service_profile( MLT_FILTER_SERVICE( filter ) ); if ( producer == NULL ) { char *background = mlt_properties_get( properties, "background" ); producer = mlt_factory_producer( profile, NULL, background ); mlt_properties_set_data( properties, "producer", producer, 0, (mlt_destructor)mlt_producer_close, NULL ); } if ( transition == NULL ) { transition = mlt_factory_transition( profile, "qtblend", NULL ); mlt_properties_set_data( properties, "transition", transition, 0, (mlt_destructor)mlt_transition_close, NULL ); if ( transition ) mlt_properties_set_int( MLT_TRANSITION_PROPERTIES( transition ), "b_alpha", 1 ); } if ( producer != NULL && transition != NULL ) { mlt_position position = mlt_filter_get_position( filter, frame ); mlt_properties frame_properties = MLT_FRAME_PROPERTIES( frame ); mlt_position in = mlt_filter_get_in( filter ); mlt_position out = mlt_filter_get_out( filter ); double consumer_ar = mlt_profile_sar( profile ); mlt_transition_set_in_and_out( transition, in, out ); if ( out > 0 ) { mlt_properties_set_position( MLT_PRODUCER_PROPERTIES( producer ), "length", out - in + 1 ); mlt_producer_set_in_and_out( producer, in, out ); } mlt_producer_seek( producer, in + position ); mlt_frame_set_position( frame, position ); mlt_properties_pass( MLT_PRODUCER_PROPERTIES( producer ), properties, "producer." ); mlt_properties_pass( MLT_TRANSITION_PROPERTIES( transition ), properties, "transition." ); mlt_service_get_frame( MLT_PRODUCER_SERVICE( producer ), &a_frame, 0 ); mlt_frame_set_position( a_frame, in + position ); // Set the rescale interpolation to match the frame mlt_properties_set( MLT_FRAME_PROPERTIES( a_frame ), "rescale.interp", mlt_properties_get( frame_properties, "rescale.interp" ) ); // Special case - aspect_ratio = 0 if ( mlt_frame_get_aspect_ratio( frame ) == 0 ) mlt_frame_set_aspect_ratio( frame, consumer_ar ); if ( mlt_frame_get_aspect_ratio( a_frame ) == 0 ) mlt_frame_set_aspect_ratio( a_frame, consumer_ar ); // Add the qtblend transition onto the frame stack mlt_service_unlock( MLT_FILTER_SERVICE( filter ) ); mlt_transition_process( transition, a_frame, frame ); if ( mlt_properties_get_int( properties, "use_normalised" ) ) { // Use the normalised width & height mlt_profile profile = mlt_service_profile( MLT_FILTER_SERVICE( filter ) ); *width = profile->width; *height = profile->height; } mlt_frame_get_image( a_frame, image, format, width, height, writable ); mlt_properties_set_data( frame_properties, "affine_frame", a_frame, 0, (mlt_destructor)mlt_frame_close, NULL ); mlt_frame_set_image( frame, *image, *width * *height * 4, NULL ); //mlt_frame_set_alpha( frame, mlt_frame_get_alpha_mask( a_frame ), *width * *height, NULL ); } else { mlt_service_unlock( MLT_FILTER_SERVICE( filter ) ); } } return error; }
int main( int argc, char **argv ) { char temp[ 132 ]; char *file1 = NULL; char *file2 = NULL; char *wipe = NULL; mlt_factory_init( "../modules" ); if ( argc < 4 ) { fprintf( stderr, "usage: luma file1.mpeg file2.mpeg wipe.pgm\n" ); return 1; } else { file1 = argv[ 1 ]; file2 = argv[ 2 ]; wipe = argv[ 3 ]; } // Start the consumer... mlt_consumer consumer = mlt_factory_consumer( "bluefish", "NTSC" ); // Create the producer(s) mlt_producer dv1 = mlt_factory_producer( "mcmpeg", file1 ); mlt_producer dv2 = mlt_factory_producer( "mcmpeg", file2 ); mlt_playlist playlist1 = mlt_playlist_init(); mlt_playlist_append_io( playlist1, dv1, 0.0, 5.0 ); mlt_playlist playlist2 = mlt_playlist_init(); mlt_playlist_blank( playlist2, 2.9 ); mlt_playlist_append( playlist2, dv2 ); // Register producers(s) with a multitrack object mlt_multitrack multitrack = mlt_multitrack_init( ); mlt_multitrack_connect( multitrack, mlt_playlist_producer( playlist1 ), 0 ); mlt_multitrack_connect( multitrack, mlt_playlist_producer( playlist2 ), 1 ); // Define a transition mlt_transition transition = mlt_factory_transition( "luma", wipe ); mlt_properties_set( mlt_transition_properties( transition ), "filename", wipe ); mlt_properties_set_double( mlt_transition_properties( transition ), "softness", 0.1 ); mlt_transition_connect( transition, mlt_multitrack_service( multitrack ), 0, 1 ); mlt_transition_set_in_and_out( transition, 3.0, 5.0 ); // Buy a tractor and connect it to the filter mlt_tractor tractor = mlt_tractor_init( ); mlt_tractor_connect( tractor, mlt_transition_service( transition ) ); // Connect the tractor to the consumer mlt_consumer_connect( consumer, mlt_tractor_service( tractor ) ); // Do stuff until we're told otherwise... fprintf( stderr, "Press return to continue\n" ); fgets( temp, 132, stdin ); // Close everything... mlt_consumer_close( consumer ); mlt_tractor_close( tractor ); mlt_transition_close( transition ); mlt_multitrack_close( multitrack ); mlt_playlist_close( playlist1 ); mlt_playlist_close( playlist2 ); mlt_producer_close( dv1 ); mlt_producer_close( dv2 ); return 0; }
int main( int argc, char **argv ) { char temp[ 132 ]; char *file1 = NULL; char *text = NULL; mlt_factory_init( "../modules" ); if ( argc < 3 ) { fprintf( stderr, "usage: pango file.mpeg text_to_display\n" ); return 1; } else { file1 = argv[ 1 ]; text = argv[ 2 ]; } // Start the consumer... mlt_consumer consumer = mlt_factory_consumer( "bluefish", "NTSC" ); // Create the producer(s) mlt_playlist pl1 = mlt_playlist_init(); mlt_producer dv1 = mlt_factory_producer( "mcmpeg", file1 ); mlt_playlist_append( pl1, dv1 ); mlt_playlist pl2 = mlt_playlist_init(); mlt_producer title = mlt_factory_producer( "pango", NULL ); //"<span font_desc=\"Sans Bold 36\">Mutton <span font_desc=\"Luxi Serif Bold Oblique 36\">Lettuce</span> Tomato</span>" ); mlt_playlist_append( pl2, title ); mlt_properties_set( mlt_producer_properties( title ), "family", "Sans" ); mlt_properties_set( mlt_producer_properties( title ), "size", "36" ); mlt_properties_set( mlt_producer_properties( title ), "weight", "700" ); mlt_properties_set( mlt_producer_properties( title ), "text", text ); mlt_properties_set_int( mlt_producer_properties( title ), "bgcolor", 0x0000007f ); mlt_properties_set_int( mlt_producer_properties( title ), "pad", 8 ); mlt_properties_set_int( mlt_producer_properties( title ), "align", 1 ); mlt_properties_set_int( mlt_producer_properties( title ), "x", 200 ); mlt_properties_set_int( mlt_producer_properties( title ), "y", 40 ); mlt_properties_set_double( mlt_producer_properties( title ), "mix", 0.8 ); // Register producers(s) with a multitrack object mlt_multitrack multitrack = mlt_multitrack_init( ); mlt_multitrack_connect( multitrack, mlt_playlist_producer( pl1 ), 0 ); mlt_multitrack_connect( multitrack, mlt_playlist_producer( pl2 ), 1 ); // Define a transition mlt_transition transition = mlt_factory_transition( "composite", NULL ); mlt_transition_connect( transition, mlt_multitrack_service( multitrack ), 0, 1 ); mlt_transition_set_in_and_out( transition, 0.0, 9999.0 ); // Buy a tractor and connect it to the filter mlt_tractor tractor = mlt_tractor_init( ); mlt_tractor_connect( tractor, mlt_transition_service( transition ) ); // Connect the tractor to the consumer mlt_consumer_connect( consumer, mlt_tractor_service( tractor ) ); // Do stuff until we're told otherwise... fprintf( stderr, "Press return to continue\n" ); fgets( temp, 132, stdin ); // Close everything... mlt_consumer_close( consumer ); mlt_tractor_close( tractor ); mlt_transition_close( transition ); mlt_multitrack_close( multitrack ); mlt_playlist_close( pl1 ); mlt_playlist_close( pl2 ); mlt_producer_close( dv1 ); mlt_producer_close( title ); return 0; }