X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmodules%2Fcore%2Ffilter_watermark.c;h=33df73a235eb3525b16cfac419d2df6159c26df5;hb=37149069e20cb4042ba1eb722a35b59cb946966e;hp=4f1c5be35646ae376a792a9a8b1ef0b4f303d78f;hpb=c0a066993bcef05ec6d3ef253e84e657e32f3dde;p=mlt diff --git a/src/modules/core/filter_watermark.c b/src/modules/core/filter_watermark.c index 4f1c5be3..33df73a2 100644 --- a/src/modules/core/filter_watermark.c +++ b/src/modules/core/filter_watermark.c @@ -27,6 +27,7 @@ #include #include +#include /** Do it :-). */ @@ -48,6 +49,12 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format // 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 ) { @@ -70,11 +77,8 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format } // Create a producer if don't have one - if ( producer == NULL ) + if ( producer == NULL || ( old_resource != NULL && strcmp( resource, old_resource ) ) ) { - // Get the resource to use - char *resource = mlt_properties_get( properties, "resource" ); - // Get the factory producer service char *factory = mlt_properties_get( properties, "factory" ); @@ -89,6 +93,9 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format // Ensure that we loop mlt_properties_set( mlt_producer_properties( producer ), "eof", "loop" ); + + // Set the old resource + mlt_properties_set( properties, "_old_resource", resource ); } } @@ -124,10 +131,37 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format // Get the b frame and process with composite if successful if ( mlt_service_get_frame( service, &b_frame, 0 ) == 0 ) - mlt_transition_process( composite, frame, b_frame ); - - // Get the image - error = mlt_frame_get_image( frame, image, format, width, height, 1 ); + { + // Set the b frame to be in the same position + mlt_frame_set_position( b_frame, position ); + + 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 + { + mlt_properties a_props = mlt_frame_properties( frame ); + mlt_properties b_props = mlt_frame_properties( b_frame ); + mlt_transition_process( composite, b_frame, frame ); + mlt_properties_set( a_props, "rescale.interp", "nearest" ); + mlt_properties_set( b_props, "rescale.interp", "nearest" ); + mlt_properties_set_int( b_props, "consumer_aspect_ratio", mlt_properties_get_double( a_props, "consumer_aspect_ratio" ) ); + mlt_service_apply_filters( mlt_filter_service( this ), frame, 0 ); + error = mlt_frame_get_image( b_frame, image, format, width, height, 1 ); + mlt_properties_set_data( b_props, "image", *image, 0, NULL, NULL ); + mlt_properties_set_data( a_props, "image", *image, *width * *height * 2, mlt_pool_release, NULL ); + mlt_properties_set_int( a_props, "width", *width ); + mlt_properties_set_int( a_props, "height", *height ); + } + } // Close the b frame mlt_frame_close( b_frame ); @@ -153,7 +187,7 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame ) char *name = mlt_properties_get( mlt_filter_properties( this ), "_unique_id" ); // Assign the current position to the name - mlt_properties_set_position( properties, name, mlt_frame_get_position( frame ) ); + mlt_properties_set_position( properties, name, mlt_frame_get_position( frame ) - mlt_filter_get_in( this ) ); // Push the filter on to the stack mlt_frame_push_service( frame, this ); @@ -177,6 +211,8 @@ mlt_filter filter_watermark_init( void *arg ) mlt_properties_set( properties, "factory", "fezzik" ); if ( arg != NULL ) mlt_properties_set( properties, "resource", arg ); + // Ensure that attached filters are handled privately + mlt_properties_set_int( properties, "_filter_private", 1 ); } return this; }