mlt_producer producer_consumer_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ) { mlt_producer self = mlt_producer_new( profile ); // Encapsulate the real producer mlt_profile temp_profile = mlt_profile_clone( profile ); temp_profile->is_explicit = 0; mlt_producer real_producer = mlt_factory_producer( temp_profile, NULL, arg ); if ( self && real_producer ) { // Override some producer methods self->close = ( mlt_destructor )producer_close; self->get_frame = get_frame; // Get the properties of this producer mlt_properties properties = MLT_PRODUCER_PROPERTIES( self ); mlt_properties_set( properties, "resource", arg ); mlt_properties_pass_list( properties, MLT_PRODUCER_PROPERTIES( real_producer ), "out, length" ); // Done with the producer - will re-open later when we have the profile property mlt_producer_close( real_producer ); } else { if ( self ) mlt_producer_close( self ); if ( real_producer ) mlt_producer_close( real_producer ); self = NULL; } mlt_profile_close( temp_profile ); return self; }
mlt_producer create_playlist( int argc, char **argv ) { // We're creating a playlist here mlt_playlist playlist = mlt_playlist_init( ); // We need the playlist properties to ensure clean up mlt_properties properties = mlt_playlist_properties( playlist ); // Loop through each of the arguments int i = 0; for ( i = 1; i < argc; i ++ ) { // Definie the unique key char key[ 256 ]; // Create the producer mlt_producer producer = mlt_factory_producer( NULL, argv[ i ] ); // Add it to the playlist mlt_playlist_append( playlist, producer ); // Create a unique key for this producer sprintf( key, "producer%d", i ); // Now we need to ensure the producers are destroyed mlt_properties_set_data( properties, key, producer, 0, ( mlt_destructor )mlt_producer_close, NULL ); } // Return the playlist as a producer return mlt_playlist_producer( playlist ); }
mlt_producer create_tracks( int argc, char **argv ) { // Create the field mlt_field field = mlt_field_init( ); // Obtain the multitrack mlt_multitrack multitrack = mlt_field_multitrack( field ); // Obtain the tractor mlt_tractor tractor = mlt_field_tractor( field ); // Obtain a composite transition mlt_transition transition = mlt_factory_transition( "composite", "10%,10%:15%x15%" ); // Create track 0 mlt_producer track0 = create_playlist( argc, argv ); // Get the length of track0 mlt_position length = mlt_producer_get_playtime( track0 ); // Create the watermark track mlt_producer track1 = mlt_factory_producer( NULL, "pango:" ); // Get the properties of track1 mlt_properties properties = mlt_producer_properties( track1 ); // Set the properties mlt_properties_set( properties, "text", "Hello\nWorld" ); mlt_properties_set_position( properties, "in", 0 ); mlt_properties_set_position( properties, "out", length - 1 ); mlt_properties_set_position( properties, "length", length ); // Now set the properties on the transition properties = mlt_transition_properties( transition ); mlt_properties_set_position( properties, "in", 0 ); mlt_properties_set_position( properties, "out", length - 1 ); // Add our tracks to the multitrack mlt_multitrack_connect( multitrack, track0, 0 ); mlt_multitrack_connect( multitrack, track1, 1 ); // Now plant the transition mlt_field_plant_transition( field, transition, 0, 1 ); // Now set the properties on the transition properties = mlt_tractor_properties( tractor ); // Ensure clean up and set properties correctly mlt_properties_set_data( properties, "multitrack", multitrack, 0, ( mlt_destructor )mlt_multitrack_close, NULL ); mlt_properties_set_data( properties, "field", field, 0, ( mlt_destructor )mlt_field_close, NULL ); mlt_properties_set_data( properties, "track0", track0, 0, ( mlt_destructor )mlt_producer_close, NULL ); mlt_properties_set_data( properties, "track1", track1, 0, ( mlt_destructor )mlt_producer_close, NULL ); mlt_properties_set_data( properties, "transition", transition, 0, ( mlt_destructor )mlt_transition_close, NULL ); mlt_properties_set_position( properties, "length", length ); mlt_properties_set_position( properties, "out", length - 1 ); // Return the tractor return mlt_tractor_producer( tractor ); }
static mlt_producer mlt_producer_clone( mlt_producer self ) { mlt_producer clone = NULL; mlt_properties properties = MLT_PRODUCER_PROPERTIES( self ); char *resource = mlt_properties_get( properties, "resource" ); char *service = mlt_properties_get( properties, "mlt_service" ); mlt_profile profile = mlt_service_profile( MLT_PRODUCER_SERVICE( self ) ); mlt_events_block( mlt_factory_event_object( ), mlt_factory_event_object( ) ); if ( service != NULL ) clone = mlt_factory_producer( profile, service, resource ); if ( clone == NULL && resource != NULL ) clone = mlt_factory_producer( profile, NULL, resource ); if ( clone != NULL ) mlt_properties_inherit( MLT_PRODUCER_PROPERTIES( clone ), properties ); mlt_events_unblock( mlt_factory_event_object( ), mlt_factory_event_object( ) ); return clone; }
static mlt_producer create_from( mlt_profile profile, char *file, char *services ) { mlt_producer producer = NULL; char *temp = strdup( services ); char *service = temp; do { char *p = strchr( service, ',' ); if ( p != NULL ) *p ++ = '\0'; producer = mlt_factory_producer( profile, service, file ); service = p; } while ( producer == NULL && service != NULL ); free( temp ); return producer; }
static mlt_frame get_background_frame( mlt_producer producer ) { mlt_properties producer_properties = MLT_PRODUCER_PROPERTIES( producer ); mlt_frame bg_frame = NULL; mlt_producer color_producer = mlt_properties_get_data( producer_properties, "_color_producer", NULL ); if( !color_producer ) { mlt_profile profile = mlt_service_profile( MLT_PRODUCER_SERVICE( producer ) ); color_producer = mlt_factory_producer( profile, mlt_environment( "MLT_PRODUCER" ), "colour:" ); mlt_properties_set_data( producer_properties, "_color_producer", color_producer, 0, ( mlt_destructor )mlt_producer_close, NULL ); mlt_properties color_properties = MLT_PRODUCER_PROPERTIES( color_producer ); mlt_properties_set( color_properties, "colour", FRAME_BACKGROUND_COLOR ); } if( color_producer ) { mlt_producer_seek( color_producer, 0 ); mlt_service_get_frame( MLT_PRODUCER_SERVICE( color_producer ), &bg_frame, 0 ); } return bg_frame; }
void AsisScript::pre_judge() throw (Exception) { ScriptProps::Property& service_prop = type_spec_props->get_property("service"); if (!service_prop.Evaluable::finished()) throw_error_v(ErrorScriptFmtError,"asis producer script service should be determinated"); ScriptProps::Property& resource_prop = type_spec_props->get_property("resource"); if (!resource_prop.Evaluable::finished()) throw_error_v(ErrorScriptFmtError,"asis producer script resource should be determinated"); json_t* svc_value = service_prop.compile(); json_t* res_value = resource_prop.compile(); JsonWrap svc_wrap(svc_value,1); JsonWrap res_wrap(res_value,1); if ( !svc_value || !json_is_string(svc_value) || !strlen(json_string_value(svc_value))) throw_error_v(ErrorScriptFmtError,"asis producer script service should be string value"); if ( !res_value || !json_is_string(res_value) || !strlen(json_string_value(res_value))) throw_error_v(ErrorScriptFmtError,"asis producer script resource should be string value"); mlt_profile prof = mlt_profile_clone(MltLoader::global_profile); mlt_producer tmp_prod = mlt_factory_producer(prof, json_string_value(svc_value), json_string_value(res_value)); MltSvcWrap prod_wrap(mlt_producer_service(tmp_prod), 1); if (tmp_prod == NULL) { throw_error_v(ErrorRuntimeLoadFailed, "producer %s load failed", json_string_value(svc_value)); } if ( mlt_props ) { ScriptProps::PropIter it = mlt_props->begin(); for ( ; it!=mlt_props->end(); it++) { if ( it->second->Evaluable::finished() ) { json_t* prop_v = it->second->compile(); JsonWrap prop_wrap(prop_v, 1); switch(prop_v->type) { case JSON_INTEGER: mlt_properties_set_int64(mlt_producer_properties(tmp_prod), it->first.c_str(), json_integer_value(prop_v)); break; case JSON_REAL: mlt_properties_set_double(mlt_producer_properties(tmp_prod), it->first.c_str(), json_real_value(prop_v)); break; case JSON_STRING: mlt_properties_set(mlt_producer_properties(tmp_prod), it->first.c_str(), json_string_value(prop_v)); break; case JSON_TRUE: mlt_properties_set_int(mlt_producer_properties(tmp_prod), it->first.c_str(), 1); break; case JSON_FALSE: mlt_properties_set_int(mlt_producer_properties(tmp_prod), it->first.c_str(), 0); break; default: throw_error_v(ErrorRuntimeLoadFailed, "producer %s load failed. %s prop invalid", json_string_value(svc_value), it->first.c_str()); } } } } int in = mlt_producer_get_in(tmp_prod); int out = mlt_producer_get_out(tmp_prod); set_frame_range(in, out); if ( !mlt_props.get()) { mlt_props.reset(new ScriptProps(*this, NULL)); } json_t* jv = json_integer(in); mlt_props->add_property("in", jv); json_decref(jv); jv = json_integer(out); mlt_props->add_property("out", jv); json_decref(jv); string uuid = Vm::uuid(); type_spec_props->add_property("uuid", JsonWrap(json_string(uuid.c_str()),1).h); prod_wrap.obj = NULL; MltLoader::push_mlt_registry(mlt_producer_service(tmp_prod), uuid.c_str()); }
mlt_service SingleResourceLoader::get_asis_producer(JsonWrap js) throw (Exception) { json_t* defines = js.h; defines_tmp=js; json_t* je = json_object_get(defines, "resource"); json_t* uuid_je = json_object_get(defines, "uuid"); json_t* svc_je = json_object_get(defines, "service"); assert( je && json_is_string(je) && strlen(json_string_value(je))); assert( svc_je && json_is_string(svc_je) && strlen(json_string_value(svc_je))); assert( uuid_je && json_is_string(uuid_je) && strlen(json_string_value(uuid_je))); mlt_producer obj = MLT_PRODUCER(MltLoader::pop_mlt_registry(json_string_value(uuid_je))); if (obj == NULL) { mlt_profile profile = mlt_profile_clone(global_profile); obj = mlt_factory_producer(profile, json_string_value(svc_je), json_string_value(je)); #ifdef DEBUG std::cout << mlt_producer_properties(obj); #endif } if ( !obj ) { throw_error_v(ErrorRuntimeLoadFailed, "video producer load failed:%s", json_string_value(je)); } mlt_properties props = mlt_producer_properties(obj); je = json_object_get(defines, "props"); if (je && json_is_object(je) && json_object_size(je)) { json_t* inj = json_object_get(je,"in"), *outj = json_object_get(je,"out"); assert(inj && outj && json_is_integer(inj) && json_is_integer(outj)); mlt_producer_set_in_and_out(obj,json_integer_value(inj), json_integer_value(outj)); void* it = json_object_iter(je); while(it) { const char* k = json_object_iter_key(it); json_t* prop_je = json_object_iter_value(it); it = json_object_iter_next(je, it); if ( json_is_object(prop_je) || json_is_array(prop_je)) continue; if ( !strcmp(k,"in") || !strcmp(k,"out")) continue; switch(prop_je->type) { case JSON_INTEGER: mlt_properties_set_int64(props, k, json_integer_value(prop_je)); break; case JSON_REAL: mlt_properties_set_double(props, k, json_real_value(prop_je)); break; case JSON_STRING: mlt_properties_set(props, k, json_string_value(prop_je)); break; case JSON_TRUE: mlt_properties_set_int(props,k, 1); break; case JSON_FALSE: mlt_properties_set_int(props,k, 0); break; default: break; } } } MltSvcWrap wrap(mlt_producer_service(obj), 1); producer_tmp = obj; parse_filters(); wrap.obj = NULL; return mlt_producer_service(obj); }
static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable ) { // Error we will return int error = 0; // Get the watermark filter object mlt_filter this = mlt_frame_pop_service( frame ); // Get the properties of the filter mlt_properties properties = MLT_FILTER_PROPERTIES( this ); mlt_service_lock( MLT_FILTER_SERVICE( this ) ); // Get the producer from the filter mlt_producer producer = mlt_properties_get_data( properties, "producer", NULL ); // Get the composite from the filter mlt_transition composite = mlt_properties_get_data( properties, "composite", NULL ); // Get the resource to use char *resource = mlt_properties_get( properties, "resource" ); // Get the old resource char *old_resource = mlt_properties_get( properties, "_old_resource" ); // Create a composite if we don't have one if ( composite == NULL ) { // Create composite via the factory mlt_profile profile = mlt_service_profile( MLT_FILTER_SERVICE( this ) ); composite = mlt_factory_transition( profile, "composite", NULL ); // Register the composite for reuse/destruction if ( composite != NULL ) mlt_properties_set_data( properties, "composite", composite, 0, ( mlt_destructor )mlt_transition_close, NULL ); } // If we have one if ( composite != NULL ) { // Get the properties mlt_properties composite_properties = MLT_TRANSITION_PROPERTIES( composite ); // Pass all the composite. properties on the filter down mlt_properties_pass( composite_properties, properties, "composite." ); if ( mlt_properties_get( properties, "composite.out" ) == NULL ) mlt_properties_set_int( composite_properties, "out", mlt_properties_get_int( properties, "_out" ) ); // Force a refresh mlt_properties_set_int( composite_properties, "refresh", 1 ); } // Create a producer if don't have one if ( producer == NULL || ( old_resource != NULL && strcmp( resource, old_resource ) ) ) { // Get the factory producer service char *factory = mlt_properties_get( properties, "factory" ); // Create the producer mlt_profile profile = mlt_service_profile( MLT_FILTER_SERVICE( this ) ); producer = mlt_factory_producer( profile, factory, resource ); // If we have one if ( producer != NULL ) { // Register the producer for reuse/destruction mlt_properties_set_data( properties, "producer", producer, 0, ( mlt_destructor )mlt_producer_close, NULL ); // Ensure that we loop mlt_properties_set( MLT_PRODUCER_PROPERTIES( producer ), "eof", "loop" ); // Set the old resource mlt_properties_set( properties, "_old_resource", resource ); } } if ( producer != NULL ) { // Get the producer properties mlt_properties producer_properties = MLT_PRODUCER_PROPERTIES( producer ); // Now pass all producer. properties on the filter down mlt_properties_pass( producer_properties, properties, "producer." ); } mlt_service_unlock( MLT_FILTER_SERVICE( this ) ); // Only continue if we have both producer and composite if ( composite != NULL && producer != NULL ) { // Get the service of the producer mlt_service service = MLT_PRODUCER_SERVICE( producer ); // We will get the 'b frame' from the producer mlt_frame b_frame = NULL; // Get the original producer position mlt_position position = mlt_filter_get_position( this, frame ); // Make sure the producer is in the correct position mlt_producer_seek( producer, position ); // Resetting position to appease the composite transition mlt_frame_set_position( frame, position ); // Get the b frame and process with composite if successful if ( mlt_service_get_frame( service, &b_frame, 0 ) == 0 ) { // Get the a and b frame properties mlt_properties a_props = MLT_FRAME_PROPERTIES( frame ); mlt_properties b_props = MLT_FRAME_PROPERTIES( b_frame ); mlt_profile profile = mlt_service_profile( service ); // Set the b frame to be in the same position and have same consumer requirements mlt_frame_set_position( b_frame, position ); mlt_properties_set_int( b_props, "consumer_deinterlace", mlt_properties_get_int( a_props, "consumer_deinterlace" ) || mlt_properties_get_int( properties, "deinterlace" ) ); // Check for the special case - no aspect ratio means no problem :-) if ( mlt_frame_get_aspect_ratio( b_frame ) == 0 ) mlt_frame_set_aspect_ratio( b_frame, mlt_profile_sar( profile ) ); if ( mlt_frame_get_aspect_ratio( frame ) == 0 ) mlt_frame_set_aspect_ratio( frame, mlt_profile_sar( profile ) ); if ( mlt_properties_get_int( properties, "distort" ) ) { mlt_properties_set_int( MLT_TRANSITION_PROPERTIES( composite ), "distort", 1 ); mlt_properties_set_int( a_props, "distort", 1 ); mlt_properties_set_int( b_props, "distort", 1 ); } *format = mlt_image_yuv422; if ( mlt_properties_get_int( properties, "reverse" ) == 0 ) { // Apply all filters that are attached to this filter to the b frame mlt_service_apply_filters( MLT_FILTER_SERVICE( this ), b_frame, 0 ); // Process the frame mlt_transition_process( composite, frame, b_frame ); // Get the image error = mlt_frame_get_image( frame, image, format, width, height, 1 ); } else { char temp[ 132 ]; int count = 0; uint8_t *alpha = NULL; const char *rescale = mlt_properties_get( a_props, "rescale.interp" ); if ( rescale == NULL || !strcmp( rescale, "none" ) ) rescale = "hyper"; mlt_transition_process( composite, b_frame, frame ); mlt_properties_set_int( a_props, "consumer_deinterlace", 1 ); mlt_properties_set_int( b_props, "consumer_deinterlace", 1 ); mlt_properties_set( a_props, "rescale.interp", rescale ); mlt_properties_set( b_props, "rescale.interp", rescale ); mlt_service_apply_filters( MLT_FILTER_SERVICE( this ), b_frame, 0 ); error = mlt_frame_get_image( b_frame, image, format, width, height, 1 ); alpha = mlt_frame_get_alpha_mask( b_frame ); mlt_frame_set_image( frame, *image, *width * *height * 2, NULL ); mlt_frame_set_alpha( frame, alpha, *width * *height, NULL ); mlt_properties_set_int( a_props, "width", *width ); mlt_properties_set_int( a_props, "height", *height ); mlt_properties_set_int( a_props, "progressive", 1 ); mlt_properties_inc_ref( b_props ); strcpy( temp, "_b_frame" ); while( mlt_properties_get_data( a_props, temp, NULL ) != NULL ) sprintf( temp, "_b_frame%d", count ++ ); mlt_properties_set_data( a_props, temp, b_frame, 0, ( mlt_destructor )mlt_frame_close, NULL ); } } // Close the b frame mlt_frame_close( b_frame ); } else { // Get the image from the frame without running fx error = mlt_frame_get_image( frame, image, format, width, height, 1 ); } return error; }
/** Constructor for the filter. */ mlt_filter filter_dynamictext_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ) { mlt_filter filter = mlt_filter_new(); mlt_transition transition = mlt_factory_transition( profile, "composite", NULL ); mlt_producer producer = mlt_factory_producer( profile, mlt_environment( "MLT_PRODUCER" ), "qtext:" ); // Use pango if qtext is not available. if( !producer ) producer = mlt_factory_producer( profile, mlt_environment( "MLT_PRODUCER" ), "pango:" ); if ( filter && transition && producer ) { mlt_properties my_properties = MLT_FILTER_PROPERTIES( filter ); // Register the transition for reuse/destruction mlt_properties_set_data( my_properties, "_transition", transition, 0, ( mlt_destructor )mlt_transition_close, NULL ); // Register the producer for reuse/destruction mlt_properties_set_data( my_properties, "_producer", producer, 0, ( mlt_destructor )mlt_producer_close, NULL ); // Ensure that we loop mlt_properties_set( MLT_PRODUCER_PROPERTIES( producer ), "eof", "loop" ); // Assign default values mlt_properties_set( my_properties, "argument", arg ? arg: "#timecode#" ); mlt_properties_set( my_properties, "geometry", "0%/0%:100%x100%:100" ); mlt_properties_set( my_properties, "family", "Sans" ); mlt_properties_set( my_properties, "size", "48" ); mlt_properties_set( my_properties, "weight", "400" ); mlt_properties_set( my_properties, "fgcolour", "0x000000ff" ); mlt_properties_set( my_properties, "bgcolour", "0x00000020" ); mlt_properties_set( my_properties, "olcolour", "0x00000000" ); mlt_properties_set( my_properties, "pad", "0" ); mlt_properties_set( my_properties, "halign", "left" ); mlt_properties_set( my_properties, "valign", "top" ); mlt_properties_set( my_properties, "outline", "0" ); mlt_properties_set_int( my_properties, "_filter_private", 1 ); filter->process = filter_process; } else { if( filter ) { mlt_filter_close( filter ); } if( transition ) { mlt_transition_close( transition ); } if( producer ) { mlt_producer_close( producer ); } filter = NULL; } return filter; }
int mlt_consumer_start( mlt_consumer self ) { if ( !mlt_consumer_is_stopped( self ) ) return 0; // Stop listening to the property-changed event mlt_event_block( self->event_listener ); // Get the properies mlt_properties properties = MLT_CONSUMER_PROPERTIES( self ); // Determine if there's a test card producer char *test_card = mlt_properties_get( properties, "test_card" ); // Just to make sure nothing is hanging around... pthread_mutex_lock( &self->put_mutex ); self->put = NULL; self->put_active = 1; pthread_mutex_unlock( &self->put_mutex ); // Deal with it now. if ( test_card != NULL ) { if ( mlt_properties_get_data( properties, "test_card_producer", NULL ) == NULL ) { // Create a test card producer mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( self ) ); mlt_producer producer = mlt_factory_producer( profile, NULL, test_card ); // Do we have a producer if ( producer != NULL ) { // Test card should loop I guess... mlt_properties_set( MLT_PRODUCER_PROPERTIES( producer ), "eof", "loop" ); //mlt_producer_set_speed( producer, 0 ); //mlt_producer_set_in_and_out( producer, 0, 0 ); // Set the test card on the consumer mlt_properties_set_data( properties, "test_card_producer", producer, 0, ( mlt_destructor )mlt_producer_close, NULL ); } } } else { // Allow the hash table to speed things up mlt_properties_set_data( properties, "test_card_producer", NULL, 0, NULL, NULL ); } // The profile could have changed between a stop and a restart. apply_profile_properties( self, mlt_service_profile( MLT_CONSUMER_SERVICE(self) ), properties ); // Set the frame duration in microseconds for the frame-dropping heuristic int frame_rate_num = mlt_properties_get_int( properties, "frame_rate_num" ); int frame_rate_den = mlt_properties_get_int( properties, "frame_rate_den" ); int frame_duration = 0; if ( frame_rate_num && frame_rate_den ) { frame_duration = 1000000 / frame_rate_num * frame_rate_den; } mlt_properties_set_int( properties, "frame_duration", frame_duration ); // Check and run an ante command if ( mlt_properties_get( properties, "ante" ) ) if ( system( mlt_properties_get( properties, "ante" ) ) == -1 ) mlt_log( MLT_CONSUMER_SERVICE( self ), MLT_LOG_ERROR, "system(%s) failed!\n", mlt_properties_get( properties, "ante" ) ); // Set the real_time preference self->real_time = mlt_properties_get_int( properties, "real_time" ); // For worker threads implementation, buffer must be at least # threads if ( abs( self->real_time ) > 1 && mlt_properties_get_int( properties, "buffer" ) <= abs( self->real_time ) ) mlt_properties_set_int( properties, "_buffer", abs( self->real_time ) + 1 ); // Get the image format to use for rendering threads const char* format = mlt_properties_get( properties, "mlt_image_format" ); if ( format ) { if ( !strcmp( format, "rgb24" ) ) self->format = mlt_image_rgb24; else if ( !strcmp( format, "rgb24a" ) ) self->format = mlt_image_rgb24a; else if ( !strcmp( format, "yuv420p" ) ) self->format = mlt_image_yuv420p; else if ( !strcmp( format, "none" ) ) self->format = mlt_image_none; else self->format = mlt_image_yuv422; } // Start the service if ( self->start != NULL ) return self->start( self ); return 0; }
static int get_frame( mlt_producer self, mlt_frame_ptr frame, int index ) { mlt_properties properties = MLT_PRODUCER_PROPERTIES(self); context cx = mlt_properties_get_data( properties, "context", NULL ); if ( !cx ) { // Allocate and initialize our context cx = mlt_pool_alloc( sizeof( struct context_s ) ); memset( cx, 0, sizeof( *cx ) ); mlt_properties_set_data( properties, "context", cx, 0, mlt_pool_release, NULL ); cx->self = self; char *profile_name = mlt_properties_get( properties, "profile" ); if ( !profile_name ) profile_name = mlt_properties_get( properties, "mlt_profile" ); mlt_profile profile = mlt_service_profile( MLT_PRODUCER_SERVICE( self ) ); if ( profile_name ) { cx->profile = mlt_profile_init( profile_name ); cx->profile->is_explicit = 1; } else { cx->profile = mlt_profile_clone( profile ); cx->profile->is_explicit = 0; } // Encapsulate a real producer for the resource cx->producer = mlt_factory_producer( cx->profile, NULL, mlt_properties_get( properties, "resource" ) ); if ( ( profile_name && !strcmp( profile_name, "auto" ) ) || mlt_properties_get_int( properties, "autoprofile" ) ) { mlt_profile_from_producer( cx->profile, cx->producer ); mlt_producer_close( cx->producer ); cx->producer = mlt_factory_producer( cx->profile, NULL, mlt_properties_get( properties, "resource" ) ); } // Since we control the seeking, prevent it from seeking on its own mlt_producer_set_speed( cx->producer, 0 ); cx->audio_position = -1; // We will encapsulate a consumer cx->consumer = mlt_consumer_new( cx->profile ); // Do not use _pass_list on real_time so that it defaults to 0 in the absence of // an explicit real_time property. mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( cx->consumer ), "real_time", mlt_properties_get_int( properties, "real_time" ) ); mlt_properties_pass_list( MLT_CONSUMER_PROPERTIES( cx->consumer ), properties, "buffer, prefill, deinterlace_method, rescale" ); // Connect it all together mlt_consumer_connect( cx->consumer, MLT_PRODUCER_SERVICE( cx->producer ) ); mlt_consumer_start( cx->consumer ); } // Generate a frame *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( self ) ); if ( *frame ) { // Seek the producer to the correct place // Calculate our positions double actual_position = (double) mlt_producer_frame( self ); if ( mlt_producer_get_speed( self ) != 0 ) actual_position *= mlt_producer_get_speed( self ); mlt_position need_first = floor( actual_position ); mlt_producer_seek( cx->producer, lrint( need_first * mlt_profile_fps( cx->profile ) / mlt_producer_get_fps( self ) ) ); // Get the nested frame mlt_frame nested_frame = mlt_consumer_rt_frame( cx->consumer ); // Stack the producer and our methods on the nested frame mlt_frame_push_service( *frame, nested_frame ); mlt_frame_push_service( *frame, cx ); mlt_frame_push_get_image( *frame, get_image ); mlt_frame_push_audio( *frame, nested_frame ); mlt_frame_push_audio( *frame, cx ); mlt_frame_push_audio( *frame, get_audio ); // Give the returned frame temporal identity mlt_frame_set_position( *frame, mlt_producer_position( self ) ); // Store the nested frame on the produced frame for destruction mlt_properties frame_props = MLT_FRAME_PROPERTIES( *frame ); mlt_properties_set_data( frame_props, "_producer_consumer.frame", nested_frame, 0, (mlt_destructor) mlt_frame_close, NULL ); // Inform the normalizers about our video properties mlt_properties_set_double( frame_props, "aspect_ratio", mlt_profile_sar( cx->profile ) ); mlt_properties_set_int( frame_props, "width", cx->profile->width ); mlt_properties_set_int( frame_props, "height", cx->profile->height ); mlt_properties_set_int( frame_props, "meta.media.width", cx->profile->width ); mlt_properties_set_int( frame_props, "meta.media.height", cx->profile->height ); mlt_properties_set_int( frame_props, "progressive", cx->profile->progressive ); } // Calculate the next timecode mlt_producer_prepare_next( self ); 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; }
int inigo( int argc, char **argv ) { int i; mlt_consumer consumer = NULL; mlt_producer melt = NULL; FILE *store = NULL; char *name = NULL; mlt_profile profile = NULL; int is_progress = 0; int is_silent = 0; // Construct the factory mlt_repository repo = mlt_factory_init( NULL ); for ( i = 1; i < argc; i ++ ) { // fprintf(stderr, "argv[%d] = %s\n", i, argv[i]); // Check for serialisation switch if ( !strcmp( argv[ i ], "-serialise" ) ) { name = argv[ ++ i ]; if ( name != NULL && strstr( name, ".melt" ) ) store = fopen( name, "w" ); else { if ( name == NULL || name[0] == '-' ) store = stdout; name = NULL; } } // Look for the profile option else if ( !strcmp( argv[ i ], "-profile" ) ) { const char *pname = argv[ ++ i ]; if ( pname && pname[0] != '-' ) profile = mlt_profile_init( pname ); } else if ( !strcmp( argv[ i ], "-progress" ) ) { is_progress = 1; } // Look for the query option else if ( !strcmp( argv[ i ], "-query" ) ) { const char *pname = argv[ ++ i ]; if ( pname && pname[0] != '-' ) { if ( !strcmp( pname, "consumers" ) || !strcmp( pname, "consumer" ) ) query_services( repo, consumer_type ); else if ( !strcmp( pname, "filters" ) || !strcmp( pname, "filter" ) ) query_services( repo, filter_type ); else if ( !strcmp( pname, "producers" ) || !strcmp( pname, "producer" ) ) query_services( repo, producer_type ); else if ( !strcmp( pname, "transitions" ) || !strcmp( pname, "transition" ) ) query_services( repo, transition_type ); else if ( !strncmp( pname, "consumer=", 9 ) ) query_metadata( repo, consumer_type, "consumer", strchr( pname, '=' ) + 1 ); else if ( !strncmp( pname, "filter=", 7 ) ) query_metadata( repo, filter_type, "filter", strchr( pname, '=' ) + 1 ); else if ( !strncmp( pname, "producer=", 9 ) ) query_metadata( repo, producer_type, "producer", strchr( pname, '=' ) + 1 ); else if ( !strncmp( pname, "transition=", 11 ) ) query_metadata( repo, transition_type, "transition", strchr( pname, '=' ) + 1 ); else goto query_all; } else { query_all: query_services( repo, consumer_type ); query_services( repo, filter_type ); query_services( repo, producer_type ); query_services( repo, transition_type ); fprintf( stderr, "# You can query the metadata for a specific service using:\n" "# -query <type>=<identifer>\n" "# where <type> is one of: consumer, filter, producer, or transition.\n" ); } goto exit_factory; } else if ( !strcmp( argv[ i ], "-silent" ) ) { is_silent = 1; } else if ( !strcmp( argv[ i ], "-verbose" ) ) { mlt_log_set_level( MLT_LOG_VERBOSE ); } else if ( !strcmp( argv[ i ], "-version" ) || !strcmp( argv[ i ], "--version" ) ) { fprintf( stderr, "MLT %s 0.5\n" "Copyright (C) 2002-2009 Ushodaya Enterprises Limited\n" "<http://www.mltframework.org/>\n" "This is free software; see the source for copying conditions. There is NO\n" "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n", basename( argv[0] ) ); goto exit_factory; } else if ( !strcmp( argv[ i ], "-debug" ) ) { mlt_log_set_level( MLT_LOG_DEBUG ); } } // Create profile if not set explicitly if ( profile == NULL ) profile = mlt_profile_init( NULL ); // Look for the consumer option for ( i = 1; i < argc; i ++ ) { if ( !strcmp( argv[ i ], "-consumer" ) ) { consumer = create_consumer( profile, argv[ ++ i ] ); if ( consumer ) { mlt_properties properties = MLT_CONSUMER_PROPERTIES( consumer ); while ( argv[ i + 1 ] != NULL && strstr( argv[ i + 1 ], "=" ) ) mlt_properties_parse( properties, argv[ ++ i ] ); } } } // If we have no consumer, default to sdl if ( store == NULL && consumer == NULL ) consumer = create_consumer( profile, NULL ); // Get melt producer if ( argc > 1 ) melt = mlt_factory_producer( profile, "melt", &argv[ 1 ] ); // Set transport properties on consumer and produder if ( consumer != NULL && melt != NULL ) { mlt_properties_set_data( MLT_CONSUMER_PROPERTIES( consumer ), "transport_producer", melt, 0, NULL, NULL ); mlt_properties_set_data( MLT_PRODUCER_PROPERTIES( melt ), "transport_consumer", consumer, 0, NULL, NULL ); if ( is_progress ) mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( consumer ), "progress", is_progress ); if ( is_silent ) mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( consumer ), "silent", is_silent ); } if ( argc > 1 && melt != NULL && mlt_producer_get_length( melt ) > 0 ) { // Parse the arguments for ( i = 1; i < argc; i ++ ) { if ( !strcmp( argv[ i ], "-serialise" ) ) { if ( store != stdout ) i ++; } else { if ( store != NULL ) fprintf( store, "%s\n", argv[ i ] ); i ++; while ( argv[ i ] != NULL && argv[ i ][ 0 ] != '-' ) { if ( store != NULL ) fprintf( store, "%s\n", argv[ i ] ); i += 1; } i --; } } if ( consumer != NULL && store == NULL ) { // Get melt's properties mlt_properties melt_props = MLT_PRODUCER_PROPERTIES( melt ); // Get the last group mlt_properties group = mlt_properties_get_data( melt_props, "group", 0 ); // Apply group settings mlt_properties properties = MLT_CONSUMER_PROPERTIES( consumer ); mlt_properties_inherit( properties, group ); // Connect consumer to melt mlt_consumer_connect( consumer, MLT_PRODUCER_SERVICE( melt ) ); // Start the consumer mlt_consumer_start( consumer ); // Transport functionality transport( melt, consumer ); // Stop the consumer mlt_consumer_stop( consumer ); } else if ( store != NULL && store != stdout && name != NULL ) { fprintf( stderr, "Project saved as %s.\n", name ); fclose( store ); } } else { fprintf( stderr, "Usage: %s [options] [producer [name=value]* ]+\n" "Options:\n" " -attach filter[:arg] [name=value]* Attach a filter to the output\n" " -attach-cut filter[:arg] [name=value]* Attach a filter to a cut\n" " -attach-track filter[:arg] [name=value]* Attach a filter to a track\n" " -attach-clip filter[:arg] [name=value]* Attach a filter to a producer\n" " -audio-track | -hide-video Add an audio-only track\n" " -blank frames Add blank silence to a track\n" " -consumer id[:arg] [name=value]* Set the consumer (sink)\n" " -debug Set the logging level to debug\n" " -filter filter[:arg] [name=value]* Add a filter to the current track\n" " -group [name=value]* Apply properties repeatedly\n" " -help Show this message\n" " -join clips Join multiple clips into one cut\n" " -mix length Add a mix between the last two cuts\n" " -mixer transition Add a transition to the mix\n" " -null-track | -hide-track Add a hidden track\n" " -profile name Set the processing settings\n" " -progress Display progress along with position\n" " -remove Remove the most recent cut\n" " -repeat times Repeat the last cut\n" " -query List all of the registered services\n" " -query \"consumers\" | \"consumer\"=id List consumers or show info about one\n" " -query \"filters\" | \"filter\"=id List filters or show info about one\n" " -query \"producers\" | \"producer\"=id List producers or show info about one\n" " -query \"transitions\" | \"transition\"=id List transitions, show info about one\n" " -serialise [filename] Write the commands to a text file\n" " -silent Do not display position/transport\n" " -split relative-frame Split the last cut into two cuts\n" " -swap Rearrange the last two cuts\n" " -track Add a track\n" " -transition id[:arg] [name=value]* Add a transition\n" " -verbose Set the logging level to verbose\n" " -version Show the version and copyright\n" " -video-track | -hide-audio Add a video-only track\n" "For more help: <http://www.mltframework.org/>\n", basename( argv[0] ) ); } // Close the producer if ( melt != NULL ) mlt_producer_close( melt ); // Close the consumer if ( consumer != NULL ) mlt_consumer_close( consumer ); // Close the factory mlt_profile_close( profile ); exit_factory: mlt_factory_close( ); return 0; }
static mlt_producer create_producer( mlt_profile profile, char *file ) { mlt_producer result = NULL; // 1st Line - check for service:resource handling if ( strchr( file, ':' ) ) { char *temp = strdup( file ); char *service = temp; char *resource = strchr( temp, ':' ); *resource ++ = '\0'; result = mlt_factory_producer( profile, service, resource ); free( temp ); } // 2nd Line preferences if ( result == NULL ) { int i = 0; char *lookup = strdup( file ); char *p = lookup; // Make backup of profile for determining if we need to use 'consumer' producer. mlt_profile backup_profile = mlt_profile_clone( profile ); // We only need to load the dictionary once if ( dictionary == NULL ) { char temp[ 1024 ]; sprintf( temp, "%s/core/loader.dict", mlt_environment( "MLT_DATA" ) ); dictionary = mlt_properties_load( temp ); mlt_factory_register_for_clean_up( dictionary, ( mlt_destructor )mlt_properties_close ); } // Convert the lookup string to lower case while ( *p ) { *p = tolower( *p ); p ++; } // Iterate through the dictionary for ( i = 0; result == NULL && i < mlt_properties_count( dictionary ); i ++ ) { char *name = mlt_properties_get_name( dictionary, i ); if ( fnmatch( name, lookup, 0 ) == 0 ) result = create_from( profile, file, mlt_properties_get_value( dictionary, i ) ); } // Check if the producer changed the profile - xml does this. // The consumer producer does not handle frame rate differences. if ( result && backup_profile->is_explicit && ( profile->width != backup_profile->width || profile->height != backup_profile->height || profile->sample_aspect_num != backup_profile->sample_aspect_num || profile->sample_aspect_den != backup_profile->sample_aspect_den || profile->colorspace != backup_profile->colorspace ) ) { // Restore the original profile attributes. profile->display_aspect_den = backup_profile->display_aspect_den; profile->display_aspect_num = backup_profile->display_aspect_num; profile->frame_rate_den = backup_profile->frame_rate_den; profile->frame_rate_num = backup_profile->frame_rate_num; profile->height = backup_profile->height; profile->progressive = backup_profile->progressive; profile->sample_aspect_den = backup_profile->sample_aspect_den; profile->sample_aspect_num = backup_profile->sample_aspect_num; profile->width = backup_profile->width; // Use the 'consumer' producer. mlt_producer_close( result ); result = mlt_factory_producer( profile, "consumer", file ); } mlt_profile_close( backup_profile ); free( lookup ); } // Finally, try just loading as service if ( result == NULL ) result = mlt_factory_producer( profile, file, NULL ); return result; }
mlt_producer producer_framebuffer_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ) { if ( !arg ) return NULL; mlt_producer producer = NULL; producer = calloc( 1, sizeof( struct mlt_producer_s ) ); mlt_producer_init( producer, NULL ); // Wrap loader mlt_producer real_producer; // Check if a speed was specified. /** * Speed must be appended to the filename with '?'. To play your video at 50%: melt framebuffer:my_video.mpg?0.5 * Stroboscope effect can be obtained by adding a stobe=x parameter, where x is the number of frames that will be ignored. * You can play the movie backwards by adding reverse=1 * You can freeze the clip at a determined position by adding freeze=frame_pos add freeze_after=1 to freeze only paste position or freeze_before to freeze before it **/ double speed = 0.0; char *props = strdup( arg ); char *ptr = strrchr( props, '?' ); if ( ptr ) { speed = atof( ptr + 1 ); if ( speed != 0.0 ) // If speed was valid, then strip it and the delimiter. // Otherwise, an invalid speed probably means this '?' was not a delimiter. *ptr = '\0'; } real_producer = mlt_factory_producer( profile, "abnormal", props ); free( props ); if (speed == 0.0) speed = 1.0; if ( producer != NULL && real_producer != NULL) { // Get the properties of this producer mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer ); mlt_properties_set( properties, "resource", arg); // Store the producer and fitler mlt_properties_set_data( properties, "producer", real_producer, 0, ( mlt_destructor )mlt_producer_close, NULL ); // Grab some stuff from the real_producer mlt_properties_pass_list( properties, MLT_PRODUCER_PROPERTIES( real_producer ), "length, width, height, aspect_ratio" ); if ( speed < 0 ) { speed = -speed; mlt_properties_set_int( properties, "reverse", 1 ); } if ( speed != 1.0 ) { double real_length = ( (double) mlt_producer_get_length( real_producer ) ) / speed; mlt_properties_set_position( properties, "length", real_length ); } mlt_properties_set_position( properties, "out", mlt_producer_get_length( producer ) - 1 ); // Since we control the seeking, prevent it from seeking on its own mlt_producer_set_speed( real_producer, 0 ); mlt_producer_set_speed( producer, speed ); // Override the get_frame method producer->get_frame = producer_get_frame; } else { if ( producer ) mlt_producer_close( producer ); if ( real_producer ) mlt_producer_close( real_producer ); producer = NULL; } return producer; }
static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable ) { mlt_filter filter = (mlt_filter) mlt_frame_pop_service( frame ); mlt_properties properties = MLT_FILTER_PROPERTIES( filter ); mlt_position pos = mlt_filter_get_position( filter, frame ); mlt_position len = mlt_filter_get_length2( filter, frame ); int maxdia = mlt_properties_anim_get_int( properties, "maxdiameter", pos, len ); int maxcount = mlt_properties_anim_get_int( properties, "maxcount", pos, len ); *format = mlt_image_yuv422; int error = mlt_frame_get_image( frame, image, format, width, height, 1 ); // Load svg char *factory = mlt_properties_get( properties, "factory" ); char temp[1204] = ""; sprintf( temp, "%s/oldfilm/", mlt_environment( "MLT_DATA" ) ); mlt_properties direntries = mlt_properties_new(); mlt_properties_dir_list( direntries, temp,"dust*.svg",1 ); if (!maxcount) return 0; double position = mlt_filter_get_progress( filter, frame ); srand( position * 10000 ); mlt_service_lock( MLT_FILTER_SERVICE( filter ) ); int im = rand() % maxcount; int piccount = mlt_properties_count( direntries ); while ( im-- && piccount ) { int picnum = rand() % piccount; int y1 = rand() % *height; int x1 = rand() % *width; char resource[1024] = ""; char savename[1024] = "", savename1[1024] = "", cachedy[100]; int dx = ( *width * maxdia / 100); int luma_width, luma_height; uint8_t *luma_image = NULL; uint8_t *alpha = NULL; int updown = rand() % 2; int mirror = rand() % 2; sprintf( resource, "%s", mlt_properties_get_value(direntries,picnum) ); sprintf( savename, "cache-%d-%d", picnum,dx ); sprintf( savename1, "cache-alpha-%d-%d", picnum, dx ); sprintf( cachedy, "cache-dy-%d-%d", picnum,dx ); luma_image = mlt_properties_get_data( properties , savename , NULL ); alpha = mlt_properties_get_data( properties , savename1 , NULL ); if ( luma_image == NULL || alpha == NULL ) { mlt_profile profile = mlt_service_profile( MLT_FILTER_SERVICE( filter ) ); mlt_producer producer = mlt_factory_producer( profile, factory, resource ); if ( producer != NULL ) { mlt_properties producer_properties = MLT_PRODUCER_PROPERTIES( producer ); mlt_properties_set( producer_properties, "eof", "loop" ); mlt_frame luma_frame = NULL; if ( mlt_service_get_frame( MLT_PRODUCER_SERVICE( producer ), &luma_frame, 0 ) == 0 ) { mlt_image_format luma_format = mlt_image_yuv422; luma_width = dx; luma_height = luma_width * mlt_properties_get_int( MLT_FRAME_PROPERTIES ( luma_frame ) , "height" ) / mlt_properties_get_int( MLT_FRAME_PROPERTIES ( luma_frame ) , "width" ); mlt_properties_set( MLT_FRAME_PROPERTIES( luma_frame ), "rescale.interp", "best" );// none/nearest/tiles/hyper mlt_frame_get_image( luma_frame, &luma_image, &luma_format, &luma_width, &luma_height, 0 ); alpha = mlt_frame_get_alpha_mask (luma_frame ); uint8_t* savealpha = mlt_pool_alloc( luma_width * luma_height ); uint8_t* savepic = mlt_pool_alloc( luma_width * luma_height * 2); if ( savealpha && savepic ) { memcpy( savealpha, alpha , luma_width * luma_height ); memcpy( savepic, luma_image , luma_width * luma_height * 2 ); mlt_properties_set_data( properties, savename, savepic, luma_width * luma_height * 2, mlt_pool_release, NULL ); mlt_properties_set_data( properties, savename1, savealpha, luma_width * luma_height, mlt_pool_release, NULL ); mlt_properties_set_int( properties, cachedy, luma_height ); overlay_image( *image, *width, *height, luma_image, luma_width, luma_height, alpha, x1, y1, updown, mirror ); } else { if ( savealpha ) mlt_pool_release( savealpha ); if ( savepic ) mlt_pool_release( savepic ); } mlt_frame_close( luma_frame ); } mlt_producer_close( producer ); } } else { overlay_image ( *image, *width, *height, luma_image, dx, mlt_properties_get_int ( properties, cachedy ), alpha, x1, y1, updown, mirror ); } } mlt_service_unlock( MLT_FILTER_SERVICE( filter ) ); if (piccount>0 ) return 0; if ( error == 0 && *image ) { int h = *height; int w = *width; int im = rand() % maxcount; while ( im-- ) { int type = im % 2; int y1 = rand() % h; int x1 = rand() % w; int dx = rand() % maxdia; int dy = rand() % maxdia; int x=0, y=0; double v = 0.0; for ( x = -dx ; x < dx ; x++ ) { for ( y = -dy ; y < dy ; y++ ) { if ( x1 + x < w && x1 + x > 0 && y1 + y < h && y1 + y > 0 ){ uint8_t *pix = *image + (y+y1) * w * 2 + (x + x1) * 2; v=pow((double) x /(double)dx * 5.0, 2.0) + pow((double)y / (double)dy * 5.0, 2.0); if (v>10) v=10; v = 1.0 - ( v / 10.0 ); switch(type) { case 0: *pix -= (*pix) * v; break; case 1: *pix += ( 255-*pix ) * v; break; } } } } } } return error; }
bool ServiceManager::initialize(int width, int height) { if (effects) return true; mlt_properties properties = MLT_SERVICE_PROPERTIES(service); // Create and initialize Effects const char* fileName = mlt_properties_get(properties, "resource"); if (!fileName) { mlt_log(service, MLT_LOG_ERROR, "No 'resource' property found\n"); return false; } bool isTransparent = mlt_properties_get_int(properties, "transparent") || mlt_service_identify(service) == filter_type; parameters = new ServiceParameters(service); effects = WebVfx::createEffects(fileName, width, height, parameters, isTransparent); if (!effects) { mlt_log(service, MLT_LOG_ERROR, "Failed to create WebVfx Effects for resource %s\n", fileName); return false; } // Iterate over image map - save source and target image names, // and create an ImageProducer for each extra image. char* factory = mlt_properties_get(properties, "factory"); WebVfx::Effects::ImageTypeMapIterator it(effects->getImageTypeMap()); while (it.hasNext()) { it.next(); const QString& imageName = it.key(); switch (it.value()) { case WebVfx::Effects::SourceImageType: sourceImageName = imageName; break; case WebVfx::Effects::TargetImageType: targetImageName = imageName; break; case WebVfx::Effects::ExtraImageType: { if (!imageProducers) imageProducers = new std::vector<ImageProducer*>(3); // Property prefix "producer.<name>." QString producerPrefix("producer."); producerPrefix.append(imageName).append("."); // Find producer.<name>.resource property QString resourceName(producerPrefix); resourceName.append("resource"); char* resource = mlt_properties_get(properties, resourceName.toLatin1().constData()); if (resource) { mlt_producer producer = mlt_factory_producer(mlt_service_profile(service), factory, resource); if (!producer) { mlt_log(service, MLT_LOG_ERROR, "WebVfx failed to create extra image producer for %s\n", resourceName.toLatin1().constData()); return false; } // Copy producer.<name>.* properties onto producer mlt_properties_pass(MLT_PRODUCER_PROPERTIES(producer), properties, producerPrefix.toLatin1().constData()); // Append ImageProducer to vector imageProducers->insert(imageProducers->end(), new ImageProducer(imageName, producer)); } else mlt_log(service, MLT_LOG_WARNING, "WebVfx no producer resource property specified for extra image %s\n", resourceName.toLatin1().constData()); break; } default: mlt_log(service, MLT_LOG_ERROR, "Invalid WebVfx image type %d\n", it.value()); break; } } return true; }
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; }
mlt_producer create_producer( char *file ) { mlt_producer result = NULL; // 1st Line preferences if ( strstr( file, ".melt" ) ) { char *args[ 2 ] = { file, NULL }; result = mlt_factory_producer( "melt", args ); } 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, ".dat" ) ) 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 ); // 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 ); return result; }
void VideoScript::pre_judge() throw (Exception) { const ScriptParam* inparam = get_param_info("in"); const ScriptParam* outparam = get_param_info("out"); const ScriptParam* resparam = get_param_info("resource"); if ( !inparam || inparam->param_style != ScriptParams::PosParam || !outparam || outparam->param_style != ScriptParams::PosParam) { throw_error_v(ErrorScriptArgInvalid, "in/out position param is required for %s script", Vm::proc_type_names[VIDEO_RESOURCE_SCRIPT]); } if ( !resparam || resparam->param_style != ScriptParams::ScalarParam ) { throw_error_v(ErrorScriptArgInvalid, "resource scalar param is required for %s script", Vm::proc_type_names[VIDEO_RESOURCE_SCRIPT]); } json_t* res_arg = get_arg_value("resource"); json_t* in = get_arg_value("in"); json_t* out = get_arg_value("out"); if (!res_arg || !json_is_string(res_arg) || !strlen(json_string_value(res_arg))) { throw_error_v(ErrorScriptArgInvalid, "resource arg is required for %s script", Vm::proc_type_names[VIDEO_RESOURCE_SCRIPT]); } if ( !in || !json_is_integer(in) ) { throw_error_v(ErrorScriptArgInvalid, "in arg is required for %s script", Vm::proc_type_names[VIDEO_RESOURCE_SCRIPT]); } if ( !out || !json_is_integer(out) ) { throw_error_v(ErrorScriptArgInvalid, "out arg is required for %s script", Vm::proc_type_names[VIDEO_RESOURCE_SCRIPT]); } string path(json_string_value(res_arg)); mlt_profile profile = mlt_profile_clone(MltLoader::global_profile); mlt_producer prod = mlt_factory_producer(profile, "loader", path.c_str()); if ( prod == NULL ) { throw_error_v(ErrorScriptArgInvalid, "out arg is required for %s script", Vm::proc_type_names[VIDEO_RESOURCE_SCRIPT]); } uuid = Vm::uuid(); MltLoader::push_mlt_registry(mlt_producer_service(prod), uuid.c_str()); //mlt_producer prod = Vm::get_stream_resource(path); int length = mlt_producer_get_length(prod); int inframe = json_integer_value(in), outframe = json_integer_value(out); json_decref(in); json_decref(out); switch (inparam->pos_type) { case ScriptParams::FramePos: if ( inframe == -1 || inframe >= length) { inframe = length - 1; } else if ( inframe < 0 ) { inframe = length + inframe; if (inframe < 0)inframe = 0; } break; case ScriptParams::TimePos: { int total_time = length * 40; if ( inframe == -1 ) { inframe = length - 1; } else if ( inframe >= 0 ) { if ( inframe > total_time) { inframe = length -1; } else { inframe = (double)inframe / 40 ; } } else { inframe = total_time + inframe; if ( inframe < 0 ) { inframe = length - 1; } else { inframe = (double)inframe/40; } } } break; } switch (outparam->pos_type) { case ScriptParams::FramePos: if ( outframe == -1 || outframe >= length) { outframe = length - 1; } else if ( outframe < 0 ) { outframe = length + outframe; if (outframe < 0)outframe = 0; } break; case ScriptParams::TimePos: { int total_time = length * 40; if ( outframe == -1 ) { outframe = length - 1; } else if ( outframe >= 0 ) { if ( outframe > total_time) { outframe = length -1; } else { outframe = (double)outframe / 40 ; } } else { outframe = total_time + outframe; if ( outframe < 0 ) { outframe = length - 1; } else { outframe = (double)outframe/40; } } } break; } if ( inframe > outframe ) { inframe ^= outframe ^= inframe ^= outframe; } set_frame_range(inframe,outframe); if ( !type_spec_props.get() ) { type_spec_props.reset(new ScriptProps(*this, NULL)); } type_spec_props->add_property("resource", res_arg); json_decref(res_arg); type_spec_props->add_property("uuid", JsonWrap(json_string(uuid.c_str()),1).h); if ( !mlt_props.get()) { mlt_props.reset(new ScriptProps(*this, NULL)); } json_t* jv = json_integer(inframe); mlt_props->add_property("in", jv); json_decref(jv); jv = json_integer(outframe); mlt_props->add_property("out", jv); json_decref(jv); //mlt_producer_set_in_and_out(prod, inframe, outframe); #ifdef DEBUG std::cout << mlt_producer_properties(prod); #endif this->path = path; //todo: check format info return; }
static int transition_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable ) { // Error we will return int error = 0; // We will get the 'b frame' from the frame stack mlt_frame b_frame = mlt_frame_pop_frame( frame ); // Get the watermark transition object mlt_transition transition = mlt_frame_pop_service( frame ); // Get the properties of the transitionfin mlt_properties properties = MLT_TRANSITION_PROPERTIES( transition ); // Get the properties of the a frame mlt_properties a_props = MLT_FRAME_PROPERTIES( frame ); mlt_service_lock( MLT_TRANSITION_SERVICE( transition ) ); // Get the composite from the transition mlt_transition composite = mlt_properties_get_data( properties, "composite", NULL ); // Look for the first filter mlt_filter filter = mlt_properties_get_data( properties, "_filter_0", NULL ); // Get the position mlt_position position = mlt_transition_get_position( transition, frame ); // Create a composite if we don't have one if ( composite == NULL ) { // Create composite via the factory mlt_profile profile = mlt_service_profile( MLT_TRANSITION_SERVICE( transition ) ); composite = mlt_factory_transition( profile, "composite", NULL ); // If we have one if ( composite != NULL ) { // Get the properties mlt_properties composite_properties = MLT_TRANSITION_PROPERTIES( composite ); // We want to ensure that we don't get a wobble... //mlt_properties_set_int( composite_properties, "distort", 1 ); mlt_properties_set_int( composite_properties, "progressive", 1 ); // Pass all the composite. properties on the transition down mlt_properties_pass( composite_properties, properties, "composite." ); // Register the composite for reuse/destruction mlt_properties_set_data( properties, "composite", composite, 0, ( mlt_destructor )mlt_transition_close, NULL ); } } else { // Pass all current properties down mlt_properties composite_properties = MLT_TRANSITION_PROPERTIES( composite ); mlt_properties_pass( composite_properties, properties, "composite." ); } // Create filters if ( filter == NULL ) { // Loop Variable int i = 0; // Number of filters created int count = 0; // Loop for all properties for ( i = 0; i < mlt_properties_count( properties ); i ++ ) { // Get the name of this property char *name = mlt_properties_get_name( properties, i ); // If the name does not contain a . and matches filter if ( strchr( name, '.' ) == NULL && !strncmp( name, "filter", 6 ) ) { // Get the filter constructor char *value = mlt_properties_get_value( properties, i ); // Create an instance if ( create_instance( transition, name, value, count ) == 0 ) count ++; } } // Look for the first filter again filter = mlt_properties_get_data( properties, "_filter_0", NULL ); } else { // Pass all properties down mlt_filter temp = NULL; // Loop Variable int i = 0; // Number of filters found int count = 0; // Loop for all properties for ( i = 0; i < mlt_properties_count( properties ); i ++ ) { // Get the name of this property char *name = mlt_properties_get_name( properties, i ); // If the name does not contain a . and matches filter if ( strchr( name, '.' ) == NULL && !strncmp( name, "filter", 6 ) ) { // Strings to hold the id and pass down key char id[ 256 ]; char key[ 256 ]; // Construct id and key sprintf( id, "_filter_%d", count ); sprintf( key, "%s.", name ); // Get the filter temp = mlt_properties_get_data( properties, id, NULL ); if ( temp != NULL ) { mlt_properties_pass( MLT_FILTER_PROPERTIES( temp ), properties, key ); count ++; } } } } mlt_properties_set_int( a_props, "width", *width ); mlt_properties_set_int( a_props, "height", *height ); // Only continue if we have both filter and composite if ( composite != NULL ) { // Get the resource of this filter (could be a shape [rectangle/circle] or an alpha provider of choice const char *resource = mlt_properties_get( properties, "resource" ); // Get the old resource in case it's changed char *old_resource = mlt_properties_get( properties, "_old_resource" ); // String to hold the filter to query on char id[ 256 ]; // Index to hold the count int i = 0; // We will get the 'b frame' from the composite only if it's NULL (region filter) if ( b_frame == NULL ) { // Copy the region b_frame = composite_copy_region( composite, frame, position ); // Ensure a destructor char *name = mlt_properties_get( properties, "_unique_id" ); mlt_properties_set_data( a_props, name, b_frame, 0, ( mlt_destructor )mlt_frame_close, NULL ); } // Properties of the B framr mlt_properties b_props = MLT_FRAME_PROPERTIES( b_frame ); // filter_only prevents copying the alpha channel of the shape to the output frame // by compositing filtered frame over itself if ( mlt_properties_get_int( properties, "filter_only" ) ) { char *name = mlt_properties_get( properties, "_unique_id" ); frame = composite_copy_region( composite, b_frame, position ); mlt_properties_set_data( b_props, name, frame, 0, ( mlt_destructor )mlt_frame_close, NULL ); } // Make sure the filter is in the correct position while ( filter != NULL ) { // Stack this filter if ( mlt_properties_get_int( MLT_FILTER_PROPERTIES( filter ), "off" ) == 0 ) mlt_filter_process( filter, b_frame ); // Generate the key for the next sprintf( id, "_filter_%d", ++ i ); // Get the next filter filter = mlt_properties_get_data( properties, id, NULL ); } // Allow filters to be attached to a region filter filter = mlt_properties_get_data( properties, "_region_filter", NULL ); if ( filter != NULL ) mlt_service_apply_filters( MLT_FILTER_SERVICE( filter ), b_frame, 0 ); // Hmm - this is probably going to go wrong.... mlt_frame_set_position( frame, position ); // Get the b frame and process with composite if successful mlt_transition_process( composite, frame, b_frame ); // If we have a shape producer copy the alpha mask from the shape frame to the b_frame if ( strcmp( resource, "rectangle" ) != 0 ) { // Get the producer from the transition mlt_producer producer = mlt_properties_get_data( properties, "producer", NULL ); // If We have no producer then create one if ( producer == NULL || ( old_resource != NULL && strcmp( resource, old_resource ) ) ) { // Get the factory producer service char *factory = mlt_properties_get( properties, "factory" ); // Store the old resource mlt_properties_set( properties, "_old_resource", resource ); // Special case circle resource if ( strcmp( resource, "circle" ) == 0 ) resource = "pixbuf:<svg width='100' height='100'><circle cx='50' cy='50' r='50' fill='black'/></svg>"; // Create the producer mlt_profile profile = mlt_service_profile( MLT_TRANSITION_SERVICE( transition ) ); producer = mlt_factory_producer( profile, factory, resource ); // If we have one if ( producer != NULL ) { // Get the producer properties mlt_properties producer_properties = MLT_PRODUCER_PROPERTIES( producer ); // Ensure that we loop mlt_properties_set( producer_properties, "eof", "loop" ); // Now pass all producer. properties on the transition down mlt_properties_pass( producer_properties, properties, "producer." ); // Register the producer for reuse/destruction mlt_properties_set_data( properties, "producer", producer, 0, ( mlt_destructor )mlt_producer_close, NULL ); } } // Now use the shape producer if ( producer != NULL ) { // We will get the alpha frame from the producer mlt_frame shape_frame = NULL; // Make sure the producer is in the correct position mlt_producer_seek( producer, position ); // Get the shape frame if ( mlt_service_get_frame( MLT_PRODUCER_SERVICE( producer ), &shape_frame, 0 ) == 0 ) { // Ensure that the shape frame will be closed mlt_properties_set_data( b_props, "shape_frame", shape_frame, 0, ( mlt_destructor )mlt_frame_close, NULL ); if ( mlt_properties_get_int(properties, "holecolor") ) { mlt_properties_set_int(b_props, "holecolor", mlt_properties_get_int(properties,"holecolor")); } // Specify the callback for evaluation b_frame->get_alpha_mask = filter_get_alpha_mask; } } } // Get the image error = mlt_frame_get_image( frame, image, format, width, height, 0 ); } mlt_service_unlock( MLT_TRANSITION_SERVICE( transition ) ); return error; }
static mlt_frame get_text_frame( mlt_producer producer, time_info* info ) { mlt_properties producer_properties = MLT_PRODUCER_PROPERTIES( producer ); mlt_producer text_producer = mlt_properties_get_data( producer_properties, "_text_producer", NULL ); mlt_profile profile = mlt_service_profile( MLT_PRODUCER_SERVICE( producer ) ); mlt_frame text_frame = NULL; if( !text_producer ) { text_producer = mlt_factory_producer( profile, mlt_environment( "MLT_PRODUCER" ), "qtext:" ); // Save the producer for future use. mlt_properties_set_data( producer_properties, "_text_producer", text_producer, 0, ( mlt_destructor )mlt_producer_close, NULL ); // Calculate the font size. char font_size[MAX_TEXT_LEN]; snprintf( font_size, MAX_TEXT_LEN - 1, "%dpx", profile->height * TEXT_SIZE_RATIO / 100 ); // Configure the producer. mlt_properties text_properties = MLT_PRODUCER_PROPERTIES( text_producer ); mlt_properties_set( text_properties, "size", font_size ); mlt_properties_set( text_properties, "weight", "400" ); mlt_properties_set( text_properties, "fgcolour", TEXT_FOREGROUND_COLOR ); mlt_properties_set( text_properties, "bgcolour", TEXT_BACKGROUND_COLOR ); mlt_properties_set( text_properties, "pad", "0" ); mlt_properties_set( text_properties, "outline", "0" ); mlt_properties_set( text_properties, "align", "center" ); } if( text_producer ) { mlt_properties text_properties = MLT_PRODUCER_PROPERTIES( text_producer ); char* style = mlt_properties_get( producer_properties, "style" ); char text[MAX_TEXT_LEN] = ""; // Apply the time style if( !strcmp( style, "frames" ) ) { snprintf( text, MAX_TEXT_LEN - 1, MLT_POSITION_FMT, info->position ); } else if( !strcmp( style, "timecode" ) ) { snprintf( text, MAX_TEXT_LEN - 1, "%02d:%02d:%02d%c%0*d", info->hours, info->minutes, info->seconds, info->sep, ( info->fps > 999? 4 : info->fps > 99? 3 : 2 ), info->frames ); } else if( !strcmp( style, "clock" ) ) { snprintf( text, MAX_TEXT_LEN - 1, "%.2d:%.2d:%.2d", info->hours, info->minutes, info->seconds ); } else if( !strcmp( style, "seconds+1" ) ) { snprintf( text, MAX_TEXT_LEN - 1, "%d", info->seconds + 1 ); } else // seconds { snprintf( text, MAX_TEXT_LEN - 1, "%d", info->seconds ); } mlt_properties_set( text_properties, "text", text ); // Get the frame. mlt_service_get_frame( MLT_PRODUCER_SERVICE( text_producer ), &text_frame, 0 ); } return text_frame; }
int main( int argc, char **argv ) { int i; mlt_consumer consumer = NULL; FILE *store = NULL; char *name = NULL; mlt_profile profile = NULL; int is_progress = 0; int is_silent = 0; mlt_profile backup_profile; // Handle abnormal exit situations. signal( SIGSEGV, abnormal_exit_handler ); signal( SIGILL, abnormal_exit_handler ); signal( SIGABRT, abnormal_exit_handler ); // Construct the factory mlt_repository repo = mlt_factory_init( NULL ); #if defined(WIN32) && !defined(MELT_NOSDL) is_silent = 1; #endif for ( i = 1; i < argc; i ++ ) { // Check for serialisation switch if ( !strcmp( argv[ i ], "-serialise" ) ) { name = argv[ ++ i ]; if ( name != NULL && strstr( name, ".melt" ) ) store = fopen( name, "w" ); else { if ( name == NULL || name[0] == '-' ) store = stdout; name = NULL; } } // Look for the profile option else if ( !strcmp( argv[ i ], "-profile" ) ) { const char *pname = argv[ ++ i ]; if ( pname && pname[0] != '-' ) profile = mlt_profile_init( pname ); } else if ( !strcmp( argv[ i ], "-progress" ) ) { is_progress = 1; } else if ( !strcmp( argv[ i ], "-progress2" ) ) { is_progress = 2; } // Look for the query option else if ( !strcmp( argv[ i ], "-query" ) ) { const char *pname = argv[ ++ i ]; if ( pname && pname[0] != '-' ) { if ( !strcmp( pname, "consumers" ) || !strcmp( pname, "consumer" ) ) query_services( repo, consumer_type ); else if ( !strcmp( pname, "filters" ) || !strcmp( pname, "filter" ) ) query_services( repo, filter_type ); else if ( !strcmp( pname, "producers" ) || !strcmp( pname, "producer" ) ) query_services( repo, producer_type ); else if ( !strcmp( pname, "transitions" ) || !strcmp( pname, "transition" ) ) query_services( repo, transition_type ); else if ( !strcmp( pname, "profiles" ) || !strcmp( pname, "profile" ) ) query_profiles(); else if ( !strcmp( pname, "presets" ) || !strcmp( pname, "preset" ) ) query_presets(); else if ( !strncmp( pname, "format", 6 ) ) query_formats(); else if ( !strncmp( pname, "acodec", 6 ) || !strcmp( pname, "audio_codecs" ) ) query_acodecs(); else if ( !strncmp( pname, "vcodec", 6 ) || !strcmp( pname, "video_codecs" ) ) query_vcodecs(); else if ( !strncmp( pname, "consumer=", 9 ) ) query_metadata( repo, consumer_type, "consumer", strchr( pname, '=' ) + 1 ); else if ( !strncmp( pname, "filter=", 7 ) ) query_metadata( repo, filter_type, "filter", strchr( pname, '=' ) + 1 ); else if ( !strncmp( pname, "producer=", 9 ) ) query_metadata( repo, producer_type, "producer", strchr( pname, '=' ) + 1 ); else if ( !strncmp( pname, "transition=", 11 ) ) query_metadata( repo, transition_type, "transition", strchr( pname, '=' ) + 1 ); else if ( !strncmp( pname, "profile=", 8 ) ) query_profile( strchr( pname, '=' ) + 1 ); else if ( !strncmp( pname, "preset=", 7 ) ) query_preset( strchr( pname, '=' ) + 1 ); else goto query_all; } else { query_all: query_services( repo, consumer_type ); query_services( repo, filter_type ); query_services( repo, producer_type ); query_services( repo, transition_type ); fprintf( stdout, "# You can query the metadata for a specific service using:\n" "# -query <type>=<identifer>\n" "# where <type> is one of: consumer, filter, producer, or transition.\n" ); } goto exit_factory; } else if ( !strcmp( argv[ i ], "-silent" ) ) { is_silent = 1; } else if ( !strcmp( argv[ i ], "-verbose" ) ) { mlt_log_set_level( MLT_LOG_VERBOSE ); } else if ( !strcmp( argv[ i ], "-version" ) || !strcmp( argv[ i ], "--version" ) ) { fprintf( stdout, "%s " VERSION "\n" "Copyright (C) 2002-2013 Ushodaya Enterprises Limited\n" "<http://www.mltframework.org/>\n" "This is free software; see the source for copying conditions. There is NO\n" "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n", basename( argv[0] ) ); goto exit_factory; } else if ( !strcmp( argv[ i ], "-debug" ) ) { mlt_log_set_level( MLT_LOG_DEBUG ); } } if ( !is_silent && !isatty( STDIN_FILENO ) && !is_progress ) is_progress = 1; // Create profile if not set explicitly if ( getenv( "MLT_PROFILE" ) ) profile = mlt_profile_init( NULL ); if ( profile == NULL ) profile = mlt_profile_init( NULL ); else profile->is_explicit = 1; // Look for the consumer option to load profile settings from consumer properties backup_profile = mlt_profile_clone( profile ); load_consumer( &consumer, profile, argc, argv ); // If the consumer changed the profile, then it is explicit. if ( backup_profile && !profile->is_explicit && ( profile->width != backup_profile->width || profile->height != backup_profile->height || profile->sample_aspect_num != backup_profile->sample_aspect_num || profile->sample_aspect_den != backup_profile->sample_aspect_den || profile->frame_rate_den != backup_profile->frame_rate_den || profile->frame_rate_num != backup_profile->frame_rate_num || profile->colorspace != backup_profile->colorspace ) ) profile->is_explicit = 1; mlt_profile_close( backup_profile ); // Get melt producer if ( argc > 1 ) melt = mlt_factory_producer( profile, "melt", &argv[ 1 ] ); if ( melt ) { // Generate an automatic profile if needed. if ( ! profile->is_explicit ) { mlt_profile_from_producer( profile, melt ); mlt_producer_close( melt ); melt = mlt_factory_producer( profile, "melt", &argv[ 1 ] ); } // Reload the consumer with the fully qualified profile. // The producer or auto-profile could have changed the profile. load_consumer( &consumer, profile, argc, argv ); // See if producer has consumer already attached if ( !store && !consumer ) { consumer = MLT_CONSUMER( mlt_service_consumer( MLT_PRODUCER_SERVICE( melt ) ) ); if ( consumer ) { mlt_properties_inc_ref( MLT_CONSUMER_PROPERTIES(consumer) ); // because we explicitly close it mlt_properties_set_data( MLT_CONSUMER_PROPERTIES(consumer), "transport_callback", transport_action, 0, NULL, NULL ); } } // If we have no consumer, default to sdl if ( store == NULL && consumer == NULL ) consumer = create_consumer( profile, NULL ); } // Set transport properties on consumer and produder if ( consumer != NULL && melt != NULL ) { mlt_properties_set_data( MLT_CONSUMER_PROPERTIES( consumer ), "transport_producer", melt, 0, NULL, NULL ); mlt_properties_set_data( MLT_PRODUCER_PROPERTIES( melt ), "transport_consumer", consumer, 0, NULL, NULL ); if ( is_progress ) mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( consumer ), "progress", is_progress ); if ( is_silent ) mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( consumer ), "silent", is_silent ); } if ( argc > 1 && melt != NULL && mlt_producer_get_length( melt ) > 0 ) { // Parse the arguments for ( i = 1; i < argc; i ++ ) { if ( !strcmp( argv[ i ], "-jack" ) ) { setup_jack_transport( consumer, profile ); } else if ( !strcmp( argv[ i ], "-serialise" ) ) { if ( store != stdout ) i ++; } else { if ( store != NULL ) fprintf( store, "%s\n", argv[ i ] ); i ++; while ( argv[ i ] != NULL && argv[ i ][ 0 ] != '-' ) { if ( store != NULL ) fprintf( store, "%s\n", argv[ i ] ); i += 1; } i --; } } if ( consumer != NULL && store == NULL ) { // Get melt's properties mlt_properties melt_props = MLT_PRODUCER_PROPERTIES( melt ); // Get the last group mlt_properties group = mlt_properties_get_data( melt_props, "group", 0 ); // Apply group settings mlt_properties properties = MLT_CONSUMER_PROPERTIES( consumer ); mlt_properties_inherit( properties, group ); // Connect consumer to melt mlt_consumer_connect( consumer, MLT_PRODUCER_SERVICE( melt ) ); // Start the consumer mlt_events_listen( properties, consumer, "consumer-fatal-error", ( mlt_listener )on_fatal_error ); if ( mlt_consumer_start( consumer ) == 0 ) { // Try to exit gracefully upon these signals signal( SIGINT, stop_handler ); signal( SIGTERM, stop_handler ); #ifndef WIN32 signal( SIGHUP, stop_handler ); signal( SIGPIPE, stop_handler ); #endif // Transport functionality transport( melt, consumer ); // Stop the consumer mlt_consumer_stop( consumer ); } } else if ( store != NULL && store != stdout && name != NULL ) { fprintf( stderr, "Project saved as %s.\n", name ); fclose( store ); } } else { show_usage( argv[0] ); } // Disconnect producer from consumer to prevent ref cycles from closing services if ( consumer ) { mlt_consumer_connect( consumer, NULL ); mlt_events_fire( MLT_CONSUMER_PROPERTIES(consumer), "consumer-cleanup", NULL); } // Close the producer if ( melt != NULL ) mlt_producer_close( melt ); // Close the consumer if ( consumer != NULL ) mlt_consumer_close( consumer ); // Close the factory mlt_profile_close( profile ); exit_factory: // Workaround qmelt on OS X from crashing at exit. #if !defined(__MACH__) || !defined(QT_GUI_LIB) mlt_factory_close( ); #endif return 0; }
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; }