mlt_frame mlt_filter_process( mlt_filter self, mlt_frame frame ) { mlt_properties properties = MLT_FILTER_PROPERTIES( self ); int disable = mlt_properties_get_int( properties, "disable" ); const char *unique_id = mlt_properties_get( properties, "_unique_id" ); mlt_position position = mlt_frame_get_position( frame ); char name[30]; // Make the properties key from unique id snprintf( name, sizeof(name), "pos.%s", unique_id ); name[sizeof(name) -1] = '\0'; // Save the position on the frame mlt_properties_set_position( MLT_FRAME_PROPERTIES( frame ), name, position ); if ( disable || self->process == NULL ) { return frame; } else { // Add a reference to this filter on the frame mlt_properties_inc_ref( MLT_FILTER_PROPERTIES(self) ); snprintf( name, sizeof(name), "filter.%s", unique_id ); name[sizeof(name) -1] = '\0'; mlt_properties_set_data( MLT_FRAME_PROPERTIES(frame), name, self, 0, (mlt_destructor) mlt_filter_close, NULL ); return self->process( self, frame ); } }
mlt_filter filter_avresample_init( char *arg ) { // Create a filter mlt_filter filter = mlt_filter_new( ); // Initialise if successful if ( filter != NULL ) { // Calculate size of the buffer int size = MAX_AUDIO_FRAME_SIZE * sizeof( int16_t ); // Allocate the buffer int16_t *buffer = mlt_pool_alloc( size ); // Assign the process method filter->process = filter_process; // Deal with argument if ( arg != NULL ) mlt_properties_set( MLT_FILTER_PROPERTIES( filter ), "frequency", arg ); // Default to 2 channel output mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "channels", 2 ); // Store the buffer mlt_properties_set_data( MLT_FILTER_PROPERTIES( filter ), "buffer", buffer, size, mlt_pool_release, NULL ); } return filter; }
static mlt_filter obtain_filter( mlt_filter filter, char *type ) { // Result to return mlt_filter result = NULL; // Miscelaneous variable int i = 0; int type_len = strlen( type ); // Get the properties of the data show filter mlt_properties filter_properties = MLT_FILTER_PROPERTIES( filter ); // Get the profile properties mlt_properties profile_properties = mlt_properties_get_data( filter_properties, "profile_properties", NULL ); // Obtain the profile_properties if we haven't already if ( profile_properties == NULL ) { char temp[ 512 ]; // Get the profile requested char *profile = mlt_properties_get( filter_properties, "resource" ); // If none is specified, pick up the default for this normalisation if ( profile == NULL ) sprintf( temp, "%s/feeds/%s/data_fx.properties", mlt_environment( "MLT_DATA" ), mlt_environment( "MLT_NORMALISATION" ) ); else if ( strchr( profile, '%' ) ) sprintf( temp, "%s/feeds/%s/%s", mlt_environment( "MLT_DATA" ), mlt_environment( "MLT_NORMALISATION" ), strchr( profile, '%' ) + 1 ); else { strncpy( temp, profile, sizeof( temp ) ); temp[ sizeof( temp ) - 1 ] = '\0'; } // Load the specified profile or use the default profile_properties = mlt_properties_load( temp ); // Store for later retrieval mlt_properties_set_data( filter_properties, "profile_properties", profile_properties, 0, ( mlt_destructor )mlt_properties_close, NULL ); } if ( profile_properties != NULL ) { for ( i = 0; i < mlt_properties_count( profile_properties ); i ++ ) { char *name = mlt_properties_get_name( profile_properties, i ); char *value = mlt_properties_get_value( profile_properties, i ); if ( result == NULL && !strcmp( name, type ) && result == NULL ) result = mlt_factory_filter( mlt_service_profile( MLT_FILTER_SERVICE( filter ) ), value, NULL ); else if ( result != NULL && !strncmp( name, type, type_len ) && name[ type_len ] == '.' ) mlt_properties_set( MLT_FILTER_PROPERTIES( result ), name + type_len + 1, value ); else if ( result != NULL ) break; } } return result; }
mlt_filter filter_mask_apply_init(mlt_profile profile, mlt_service_type type, const char *id, char *arg) { mlt_filter filter = mlt_filter_new( ); if (filter) { mlt_properties_set(MLT_FILTER_PROPERTIES(filter), "transition", arg? arg : "frei0r.composition"); mlt_properties_set(MLT_FILTER_PROPERTIES(filter), "mlt_image_format", "rgb24a"); filter->process = process; } return filter; }
mlt_filter filter_dust_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ) { mlt_filter filter = mlt_filter_new( ); if ( filter != NULL ) { filter->process = filter_process; mlt_properties_set( MLT_FILTER_PROPERTIES( filter ), "maxdiameter", "2" ); mlt_properties_set( MLT_FILTER_PROPERTIES( filter ), "maxcount", "10" ); } return filter; }
static int filter_get_audio( mlt_frame frame, void** buffer, mlt_audio_format* format, int* frequency, int* channels, int* samples ) { mlt_filter filter = (mlt_filter)mlt_frame_pop_audio( frame ); mlt_properties filter_properties = MLT_FILTER_PROPERTIES( filter ); private_data* pdata = (private_data*)filter->child; // Create the FFT filter the first time. if( !pdata->fft ) { mlt_profile profile = mlt_service_profile( MLT_FILTER_SERVICE(filter) ); pdata->fft = mlt_factory_filter( profile, "fft", NULL ); mlt_properties_set_int( MLT_FILTER_PROPERTIES( pdata->fft ), "window_size", mlt_properties_get_int( filter_properties, "window_size" ) ); if( !pdata->fft ) { mlt_log_warning( MLT_FILTER_SERVICE(filter), "Unable to create FFT.\n" ); return 1; } } mlt_properties fft_properties = MLT_FILTER_PROPERTIES( pdata->fft ); // The service must stay locked while using the private data mlt_service_lock( MLT_FILTER_SERVICE( filter ) ); // Perform FFT processing on the frame mlt_filter_process( pdata->fft, frame ); mlt_frame_get_audio( frame, buffer, format, frequency, channels, samples ); float* bins = (float*)mlt_properties_get_data( fft_properties, "bins", NULL ); if( bins ) { double window_level = mlt_properties_get_double( fft_properties, "window_level" ); int bin_count = mlt_properties_get_int( fft_properties, "bin_count" ); size_t bins_size = bin_count * sizeof(float); float* save_bins = (float*)mlt_pool_alloc( bins_size ); if( window_level == 1.0 ) { memcpy( save_bins, bins, bins_size ); } else { memset( save_bins, 0, bins_size ); } // Save the bin data as a property on the frame to be used in get_image() mlt_properties_set_data( MLT_FRAME_PROPERTIES(frame), pdata->fft_prop_name, save_bins, bins_size, mlt_pool_release, NULL ); } mlt_service_unlock( MLT_FILTER_SERVICE( filter ) ); return 0; }
mlt_filter filter_grain_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ) { mlt_filter filter = mlt_filter_new( ); if ( filter != NULL ) { filter->process = filter_process; mlt_properties_set( MLT_FILTER_PROPERTIES( filter ), "noise", "40" ); mlt_properties_set( MLT_FILTER_PROPERTIES( filter ), "contrast", "160" ); mlt_properties_set( MLT_FILTER_PROPERTIES( filter ), "brightness", "70" ); } return filter; }
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 position = mlt_filter_get_position( filter, frame ); mlt_position length = mlt_filter_get_length2( filter, frame ); // Get the image *format = mlt_image_yuv422; int error = mlt_frame_get_image( frame, image, format, width, height, 1 ); // Only process if we have no error and a valid colour space if ( error == 0 ) { double level = 1.0; // Use animated "level" property only if it has been set since init char* level_property = mlt_properties_get( MLT_FILTER_PROPERTIES( filter ), "level" ); if ( level_property != NULL ) { level = mlt_properties_anim_get_double( properties, "level", position, length ); } else { // Get level using old "start,"end" mechanics // Get the starting brightness level level = fabs( mlt_properties_get_double( MLT_FILTER_PROPERTIES( filter ), "start" ) ); // If there is an end adjust gain to the range if ( mlt_properties_get( MLT_FILTER_PROPERTIES( filter ), "end" ) != NULL ) { // Determine the time position of this frame in the transition duration double end = fabs( mlt_properties_get_double( MLT_FILTER_PROPERTIES( filter ), "end" ) ); level += ( end - level ) * mlt_filter_get_progress( filter, frame ); } } // Only process if level is something other than 1 if ( level != 1.0 ) { int i = *width * *height + 1; uint8_t *p = *image; int32_t m = level * ( 1 << 16 ); int32_t n = 128 * ( ( 1 << 16 ) - m ); while ( --i ) { p[0] = CLAMP( (p[0] * m) >> 16, 16, 235 ); p[1] = CLAMP( (p[1] * m + n) >> 16, 16, 240 ); p += 2; } }
mlt_filter filter_mono_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ) { mlt_filter filter = mlt_filter_new( ); if ( filter != NULL ) { filter->process = filter_process; if ( arg != NULL ) mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "channels", atoi( arg ) ); else mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "channels", -1 ); } return filter; }
mlt_filter filter_panner_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ) { mlt_filter filter = calloc( 1, sizeof( struct mlt_filter_s ) ); if ( filter != NULL && mlt_filter_init( filter, NULL ) == 0 ) { filter->process = filter_process; if ( arg != NULL ) mlt_properties_set_double( MLT_FILTER_PROPERTIES( filter ), "start", atof( arg ) ); mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "channel", -1 ); mlt_properties_set( MLT_FILTER_PROPERTIES( filter ), "split", NULL ); } return filter; }
mlt_filter filter_charcoal_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ) { mlt_filter filter = mlt_filter_new( ); if ( filter != NULL ) { filter->process = filter_process; mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "x_scatter", 1 ); mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "y_scatter", 1 ); mlt_properties_set_double( MLT_FILTER_PROPERTIES( filter ), "scale", 1.5 ); mlt_properties_set_double( MLT_FILTER_PROPERTIES( filter ), "mix", 0.0 ); } return filter; }
mlt_filter filter_wave_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ) { mlt_filter filter = mlt_filter_new( ); if ( filter ) { filter->process = filter_process; mlt_properties_set( MLT_FILTER_PROPERTIES( filter ), "start", arg == NULL ? "10" : arg); mlt_properties_set( MLT_FILTER_PROPERTIES( filter ), "speed", "5"); mlt_properties_set( MLT_FILTER_PROPERTIES( filter ), "deformX", "1"); mlt_properties_set( MLT_FILTER_PROPERTIES( filter ), "deformY", "1"); mlt_properties_set( MLT_FILTER_PROPERTIES( filter ), "wave", NULL); } return filter; }
mlt_filter filter_channelcopy_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ) { mlt_filter filter = mlt_filter_new( ); if ( filter != NULL ) { filter->process = filter_process; if ( arg != NULL ) mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "to", atoi( arg ) ); else mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "to", 1 ); if ( strcmp(id, "channelswap") == 0 ) mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "swap", 1 ); } return filter; }
void mlt_service_apply_filters( mlt_service self, mlt_frame frame, int index ) { int i; mlt_properties frame_properties = MLT_FRAME_PROPERTIES( frame ); mlt_properties service_properties = MLT_SERVICE_PROPERTIES( self ); mlt_service_base *base = self->local; mlt_position position = mlt_frame_get_position( frame ); mlt_position self_in = mlt_properties_get_position( service_properties, "in" ); mlt_position self_out = mlt_properties_get_position( service_properties, "out" ); if ( index == 0 || mlt_properties_get_int( service_properties, "_filter_private" ) == 0 ) { // Process the frame with the attached filters for ( i = 0; i < base->filter_count; i ++ ) { if ( base->filters[ i ] != NULL ) { mlt_position in = mlt_filter_get_in( base->filters[ i ] ); mlt_position out = mlt_filter_get_out( base->filters[ i ] ); int disable = mlt_properties_get_int( MLT_FILTER_PROPERTIES( base->filters[ i ] ), "disable" ); if ( !disable && ( ( in == 0 && out == 0 ) || ( position >= in && ( position <= out || out == 0 ) ) ) ) { mlt_properties_set_position( frame_properties, "in", in == 0 ? self_in : in ); mlt_properties_set_position( frame_properties, "out", out == 0 ? self_out : out ); mlt_filter_process( base->filters[ i ], frame ); mlt_service_apply_filters( MLT_FILTER_SERVICE( base->filters[ i ] ), frame, index + 1 ); } } } } }
int mlt_service_detach( mlt_service self, mlt_filter filter ) { int error = self == NULL || filter == NULL; if ( error == 0 ) { int i = 0; mlt_service_base *base = self->local; mlt_properties properties = MLT_SERVICE_PROPERTIES( self ); for ( i = 0; i < base->filter_count; i ++ ) if ( base->filters[ i ] == filter ) break; if ( i < base->filter_count ) { base->filters[ i ] = NULL; for ( i ++ ; i < base->filter_count; i ++ ) base->filters[ i - 1 ] = base->filters[ i ]; base->filter_count --; mlt_events_disconnect( MLT_FILTER_PROPERTIES( filter ), self ); mlt_filter_close( filter ); mlt_events_fire( properties, "service-changed", NULL ); } } return error; }
static void serialize_vectors( videostab self, mlt_position length ) { mlt_geometry g = mlt_geometry_init(); if ( g ) { struct mlt_geometry_item_s item; int i; // Initialize geometry item item.key = item.f[0] = item.f[1] = 1; item.f[2] = item.f[3] = item.f[4] = 0; for ( i = 0; i < length; i++ ) { // Set the geometry item item.frame = i; item.x = self->pos_h[i].x; item.y = self->pos_h[i].y; // Add the geometry item mlt_geometry_insert( g, &item ); } // Put the analysis results in a property mlt_geometry_set_length( g, length ); mlt_properties_set_data( MLT_FILTER_PROPERTIES( self->parent ), "vectors", g, 0, (mlt_destructor) mlt_geometry_close, (mlt_serialiser) mlt_geometry_serialise ); } }
static int attach_boundry_to_frame( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable ) { // Get the filter object mlt_filter filter = mlt_frame_pop_service( frame ); // Get the filter's property object mlt_properties filter_properties = MLT_FILTER_PROPERTIES(filter); // Get the frame properties mlt_properties frame_properties = MLT_FRAME_PROPERTIES(frame); // Get the frame position mlt_position position = mlt_filter_get_position( filter, frame ); mlt_service_lock( MLT_FILTER_SERVICE( filter ) ); // Get the geometry object mlt_geometry geometry = mlt_properties_get_data(filter_properties, "filter_geometry", NULL); if (geometry == NULL) { mlt_geometry geom = mlt_geometry_init(); char *arg = mlt_properties_get(filter_properties, "geometry"); // Initialize with the supplied geometry struct mlt_geometry_item_s item; mlt_geometry_parse_item( geom, &item, arg ); item.frame = 0; item.key = 1; item.mix = 100; mlt_geometry_insert( geom, &item ); mlt_geometry_interpolate( geom ); mlt_properties_set_data( filter_properties, "filter_geometry", geom, 0, (mlt_destructor)mlt_geometry_close, (mlt_serialiser)mlt_geometry_serialise ); geometry = mlt_properties_get_data(filter_properties, "filter_geometry", NULL); } mlt_service_unlock( MLT_FILTER_SERVICE( filter ) ); // Get the current geometry item mlt_geometry_item geometry_item = mlt_pool_alloc( sizeof( struct mlt_geometry_item_s ) ); mlt_geometry_fetch(geometry, geometry_item, position); // Cleanse the geometry item geometry_item->w = geometry_item->x < 0 ? geometry_item->w + geometry_item->x : geometry_item->w; geometry_item->h = geometry_item->y < 0 ? geometry_item->h + geometry_item->y : geometry_item->h; geometry_item->x = geometry_item->x < 0 ? 0 : geometry_item->x; geometry_item->y = geometry_item->y < 0 ? 0 : geometry_item->y; geometry_item->w = geometry_item->w < 0 ? 0 : geometry_item->w; geometry_item->h = geometry_item->h < 0 ? 0 : geometry_item->h; mlt_properties_set_data( frame_properties, "bounds", geometry_item, sizeof( struct mlt_geometry_item_s ), mlt_pool_release, NULL ); // Get the new image int error = mlt_frame_get_image( frame, image, format, width, height, 1 ); if( error != 0 ) mlt_properties_debug( frame_properties, "error after mlt_frame_get_image() in autotrack_rectangle attach_boundry_to_frame", stderr ); return error; }
void filter_close( mlt_filter filter ) { destruct( MLT_FILTER_PROPERTIES ( filter ) ); filter->close = NULL; filter->parent.close = NULL; mlt_service_close( &filter->parent ); }
static int jackrack_get_audio( mlt_frame frame, void **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples ) { // Get the filter service mlt_filter filter = mlt_frame_pop_audio( frame ); // Get the filter properties mlt_properties filter_properties = MLT_FILTER_PROPERTIES( filter ); int jack_frequency = mlt_properties_get_int( filter_properties, "_sample_rate" ); // Get the producer's audio *format = mlt_audio_float; mlt_frame_get_audio( frame, buffer, format, &jack_frequency, channels, samples ); // TODO: Deal with sample rate differences if ( *frequency != jack_frequency ) mlt_log_error( MLT_FILTER_SERVICE( filter ), "mismatching frequencies JACK = %d actual = %d\n", jack_frequency, *frequency ); *frequency = jack_frequency; // Initialise Jack ports and connections if needed if ( mlt_properties_get_int( filter_properties, "_samples" ) == 0 ) mlt_properties_set_int( filter_properties, "_samples", *samples ); // Get the filter-specific properties jack_ringbuffer_t **output_buffers = mlt_properties_get_data( filter_properties, "output_buffers", NULL ); jack_ringbuffer_t **input_buffers = mlt_properties_get_data( filter_properties, "input_buffers", NULL ); // pthread_mutex_t *output_lock = mlt_properties_get_data( filter_properties, "output_lock", NULL ); // pthread_cond_t *output_ready = mlt_properties_get_data( filter_properties, "output_ready", NULL ); // Process the audio float *q = (float*) *buffer; size_t size = *samples * sizeof(float); int j; // struct timespec tm = { 0, 0 }; // Write into output ringbuffer for ( j = 0; j < *channels; j++ ) { if ( jack_ringbuffer_write_space( output_buffers[j] ) >= size ) jack_ringbuffer_write( output_buffers[j], (char*)( q + j * *samples ), size ); } // Synchronization phase - wait for signal from Jack process while ( jack_ringbuffer_read_space( input_buffers[ *channels - 1 ] ) < size ) ; //pthread_cond_wait( output_ready, output_lock ); // Read from input ringbuffer for ( j = 0; j < *channels; j++, q++ ) { if ( jack_ringbuffer_read_space( input_buffers[j] ) >= size ) jack_ringbuffer_read( input_buffers[j], (char*)( q + j * *samples ), size ); } // help jack_sync() indicate when we are rolling mlt_position pos = mlt_frame_get_position( frame ); mlt_properties_set_position( filter_properties, "_last_pos", pos ); return 0; }
static void get_transform_config( VSTransformConfig* conf, mlt_filter filter, mlt_frame frame ) { mlt_properties properties = MLT_FILTER_PROPERTIES( filter ); const char* filterName = mlt_properties_get( properties, "mlt_service" ); *conf = vsTransformGetDefaultConfig( filterName ); conf->smoothing = mlt_properties_get_int( properties, "smoothing" ); conf->maxShift = mlt_properties_get_int( properties, "maxshift" ); conf->maxAngle = mlt_properties_get_double( properties, "maxangle" ); conf->crop = (VSBorderType)mlt_properties_get_int( properties, "crop" ); conf->zoom = mlt_properties_get_int( properties, "zoom" ); conf->optZoom = mlt_properties_get_int( properties, "optzoom" ); conf->zoomSpeed = mlt_properties_get_double( properties, "zoomspeed" ); conf->relative = mlt_properties_get_int( properties, "relative" ); conf->invert = mlt_properties_get_int( properties, "invert" ); if ( mlt_properties_get_int( properties, "tripod" ) != 0 ) { // Virtual tripod mode: relative=False, smoothing=0 conf->relative = 0; conf->smoothing = 0; } // by default a bicubic interpolation is selected const char *interps = mlt_properties_get( MLT_FRAME_PROPERTIES( frame ), "rescale.interp" ); conf->interpolType = VS_BiCubic; if ( strcmp( interps, "nearest" ) == 0 || strcmp( interps, "neighbor" ) == 0 ) conf->interpolType = VS_Zero; else if ( strcmp( interps, "tiles" ) == 0 || strcmp( interps, "fast_bilinear" ) == 0 ) conf->interpolType = VS_Linear; else if ( strcmp( interps, "bilinear" ) == 0 ) conf->interpolType = VS_BiLinear; }
static void check_for_reset( mlt_filter filter, int channels, int frequency ) { mlt_properties properties = MLT_FILTER_PROPERTIES( filter ); private_data* pdata = (private_data*)filter->child; if( pdata->reset ) { if( pdata->r128 ) { ebur128_destroy( &pdata->r128 ); } pdata->r128 = 0; pdata->target_gain = 0.0; pdata->start_gain = 0.0; pdata->end_gain = 0.0; pdata->reset = 0; pdata->time_elapsed_ms = 0; pdata->prev_o_pos = -1; mlt_properties_set_double( properties, "out_gain", 0.0 ); mlt_properties_set_double( properties, "in_loudness", -100.0 ); mlt_properties_set_int( properties, "reset_count", mlt_properties_get_int( properties, "reset_count") + 1 ); } if( !pdata->r128 ) { pdata->r128 = ebur128_init( channels, frequency, EBUR128_MODE_I ); ebur128_set_max_window( pdata->r128, 400 ); ebur128_set_max_history( pdata->r128, mlt_properties_get_int( properties, "window" ) * 1000.0 ); } }
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 position = mlt_frame_get_position( frame ); // Get the image *format = mlt_image_yuv422; int error = mlt_frame_get_image( frame, image, format, width, height, 0 ); // Only process if we have no error and a valid colour space if ( error == 0 ) { double factor = mlt_properties_get_double( properties, "start" ); mlt_position f_pos = mlt_filter_get_position( filter, frame ); mlt_position f_len = mlt_filter_get_length2( filter, frame ); int speed = mlt_properties_anim_get_int( properties, "speed", f_pos, f_len ); int deformX = mlt_properties_anim_get_int( properties, "deformX", f_pos, f_len ); int deformY = mlt_properties_anim_get_int( properties, "deformY", f_pos, f_len ); if ( mlt_properties_get( properties, "end" ) ) { // Determine the time position of this frame in the transition duration double end = fabs( mlt_properties_get_double( MLT_FILTER_PROPERTIES( filter ), "end" ) ); factor += ( end - factor ) * mlt_filter_get_progress( filter, frame ); } // If animated property "wave" is set, use its value. char* wave_property = mlt_properties_get( properties, "wave" ); if ( wave_property ) { factor = mlt_properties_anim_get_double( properties, "wave", f_pos, f_len ); } if (factor != 0) { int image_size = *width * (*height) * 2; uint8_t *dst = mlt_pool_alloc (image_size); DoWave(*image, *width, (*height), dst, position, speed, factor, deformX, deformY); *image = dst; mlt_frame_set_image( frame, *image, image_size, mlt_pool_release ); } } return error; }
static void draw_spectrum( mlt_filter filter, mlt_frame frame, QImage* qimg ) { mlt_properties filter_properties = MLT_FILTER_PROPERTIES( filter ); mlt_position position = mlt_filter_get_position( filter, frame ); mlt_position length = mlt_filter_get_length2( filter, frame ); mlt_rect rect = mlt_properties_anim_get_rect( filter_properties, "rect", position, length ); if ( strchr( mlt_properties_get( filter_properties, "rect" ), '%' ) ) { rect.x *= qimg->width(); rect.w *= qimg->width(); rect.y *= qimg->height(); rect.h *= qimg->height(); } char* graph_type = mlt_properties_get( filter_properties, "type" ); int mirror = mlt_properties_get_int( filter_properties, "mirror" ); int fill = mlt_properties_get_int( filter_properties, "fill" ); double tension = mlt_properties_get_double( filter_properties, "tension" ); QRectF r( rect.x, rect.y, rect.w, rect.h ); QPainter p( qimg ); if( mirror ) { // Draw two half rectangle instead of one full rectangle. r.setHeight( r.height() / 2.0 ); } setup_graph_painter( p, r, filter_properties ); setup_graph_pen( p, r, filter_properties ); int bands = mlt_properties_get_int( filter_properties, "bands" ); if ( bands == 0 ) { // "0" means match rectangle width bands = r.width(); } float* spectrum = (float*)mlt_pool_alloc( bands * sizeof(float) ); convert_fft_to_spectrum( filter, frame, bands, spectrum ); if( graph_type && graph_type[0] == 'b' ) { paint_bar_graph( p, r, bands, spectrum ); } else { paint_line_graph( p, r, bands, spectrum, tension, fill ); } if( mirror ) { // Second rectangle is mirrored. p.translate( 0, r.y() * 2 + r.height() * 2 ); p.scale( 1, -1 ); if( graph_type && graph_type[0] == 'b' ) { paint_bar_graph( p, r, bands, spectrum ); } else { paint_line_graph( p, r, bands, spectrum, tension, fill ); } } mlt_pool_release( spectrum ); p.end(); }
mlt_filter filter_vidstab_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ) { mlt_filter filter = mlt_filter_new(); vs_data* data = (vs_data*)calloc( 1, sizeof(vs_data) ); if ( filter && data ) { data->analyze_data = NULL; data->apply_data = NULL; filter->close = filter_close; filter->child = data; filter->process = process_filter; mlt_properties properties = MLT_FILTER_PROPERTIES(filter); //properties for analyze mlt_properties_set( properties, "filename", "vidstab.trf" ); mlt_properties_set( properties, "shakiness", "4" ); mlt_properties_set( properties, "accuracy", "4" ); mlt_properties_set( properties, "stepsize", "6" ); mlt_properties_set( properties, "algo", "1" ); mlt_properties_set( properties, "mincontrast", "0.3" ); mlt_properties_set( properties, "show", "0" ); mlt_properties_set( properties, "tripod", "0" ); // properties for apply mlt_properties_set( properties, "smoothing", "15" ); mlt_properties_set( properties, "maxshift", "-1" ); mlt_properties_set( properties, "maxangle", "-1" ); mlt_properties_set( properties, "crop", "0" ); mlt_properties_set( properties, "invert", "0" ); mlt_properties_set( properties, "relative", "1" ); mlt_properties_set( properties, "zoom", "0" ); mlt_properties_set( properties, "optzoom", "1" ); mlt_properties_set( properties, "zoomspeed", "0.25" ); mlt_properties_set( properties, "reload", "0" ); mlt_properties_set( properties, "vid.stab.version", LIBVIDSTAB_VERSION ); init_vslog(); } else { if( filter ) { mlt_filter_close( filter ); } if( data ) { free( data ); } filter = NULL; } return filter; }
Effect* GlslManager::add_effect( mlt_filter filter, mlt_frame frame, Effect* effect ) { Mlt::Producer producer( mlt_producer_cut_parent( mlt_frame_get_original_producer( frame ) ) ); EffectChain* chain = (EffectChain*) producer.get_data( "movit chain" ); chain->add_effect( effect ); char *unique_id = mlt_properties_get( MLT_FILTER_PROPERTIES(filter), "_unique_id" ); GlslManager::get_instance()->effect_list( producer ).set( unique_id, effect, 0 ); return effect; }
static mlt_frame process( mlt_filter filter, mlt_frame frame ) { // Set a default colorspace on the frame if not yet set by the producer. // The producer may still change it during get_image. // This way we do not have to modify each producer to set a valid colorspace. mlt_properties properties = MLT_FRAME_PROPERTIES(frame); if ( mlt_properties_get_int( properties, "colorspace" ) <= 0 ) mlt_properties_set_int( properties, "colorspace", mlt_service_profile( MLT_FILTER_SERVICE(filter) )->colorspace ); frame->convert_image = convert_image; mlt_filter cpu_csc = (mlt_filter) mlt_properties_get_data( MLT_FILTER_PROPERTIES( filter ), "cpu_csc", NULL ); mlt_properties_inc_ref( MLT_FILTER_PROPERTIES(cpu_csc) ); mlt_properties_set_data( properties, "cpu_csc", cpu_csc, 0, (mlt_destructor) mlt_filter_close, NULL ); return frame; }
static void analyze_audio( mlt_filter filter, void* buffer, int samples, int frequency ) { mlt_properties properties = MLT_FILTER_PROPERTIES( filter ); private_data* pdata = (private_data*)filter->child; int result = -1; double in_loudness = 0.0; mlt_profile profile = mlt_service_profile( MLT_FILTER_SERVICE(filter) ); double fps = mlt_profile_fps( profile ); ebur128_add_frames_float( pdata->r128, buffer, samples ); if( pdata->time_elapsed_ms < 400 ) { // Waiting for first program loudness measurement. // Use window loudness as initial guess. result = ebur128_loudness_window( pdata->r128, pdata->time_elapsed_ms, &in_loudness ); pdata->time_elapsed_ms += samples * 1000 / frequency; } else { result = ebur128_loudness_global( pdata->r128, &in_loudness ); } if( result == EBUR128_SUCCESS && in_loudness != HUGE_VAL && in_loudness != -HUGE_VAL ) { mlt_properties_set_double( properties, "in_loudness", in_loudness ); double target_loudness = mlt_properties_get_double( properties, "target_loudness" ); pdata->target_gain = target_loudness - in_loudness; // Make sure gain limits are not exceeded. double max_gain = mlt_properties_get_double( properties, "max_gain" ); double min_gain = mlt_properties_get_double( properties, "min_gain" ); if( pdata->target_gain > max_gain ) { pdata->target_gain = max_gain; } else if ( pdata->target_gain < min_gain ) { pdata->target_gain = min_gain; } } // Make sure gain does not change too quickly. pdata->start_gain = pdata->end_gain; pdata->end_gain = pdata->target_gain; double max_frame_gain = mlt_properties_get_double( properties, "max_rate" ) / fps; if( pdata->start_gain - pdata->end_gain > max_frame_gain ) { pdata->end_gain = pdata->start_gain - max_frame_gain; } else if( pdata->end_gain - pdata->start_gain > max_frame_gain ) { pdata->end_gain = pdata->start_gain + max_frame_gain; } mlt_properties_set_double( properties, "out_gain", pdata->end_gain ); }
int mlt_service_attach( mlt_service self, mlt_filter filter ) { int error = self == NULL || filter == NULL; if ( error == 0 ) { int i = 0; mlt_properties properties = MLT_SERVICE_PROPERTIES( self ); mlt_service_base *base = self->local; for ( i = 0; error == 0 && i < base->filter_count; i ++ ) if ( base->filters[ i ] == filter ) error = 1; if ( error == 0 ) { if ( base->filter_count == base->filter_size ) { base->filter_size += 10; base->filters = realloc( base->filters, base->filter_size * sizeof( mlt_filter ) ); } if ( base->filters != NULL ) { mlt_properties props = MLT_FILTER_PROPERTIES( filter ); mlt_properties_inc_ref( MLT_FILTER_PROPERTIES( filter ) ); base->filters[ base->filter_count ++ ] = filter; mlt_properties_set_data( props, "service", self, 0, NULL, NULL ); mlt_events_fire( properties, "service-changed", NULL ); mlt_events_fire( props, "service-changed", NULL ); mlt_service cp = mlt_properties_get_data( properties, "_cut_parent", NULL ); if ( cp ) mlt_events_fire( MLT_SERVICE_PROPERTIES(cp), "service-changed", NULL ); mlt_events_listen( props, self, "service-changed", ( mlt_listener )mlt_service_filter_changed ); mlt_events_listen( props, self, "property-changed", ( mlt_listener )mlt_service_filter_property_changed ); } else { error = 2; } } } return error; }
mlt_filter filter_gamma_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ) { mlt_filter filter = mlt_filter_new( ); if ( filter != NULL ) { filter->process = filter_process; mlt_properties_set( MLT_FILTER_PROPERTIES( filter ), "gamma", arg == NULL ? "1" : arg ); } return filter; }
mlt_filter filter_qtblend_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ) { mlt_filter filter = mlt_filter_new( ); if ( filter != NULL ) { filter->process = filter_process; mlt_properties_set( MLT_FILTER_PROPERTIES( filter ), "background", arg ? arg : "colour:0" ); } return filter; }