]> git.sesse.net Git - mlt/commitdiff
Enhance luma filter to work with animated filters.
authorDan Dennedy <dan@dennedy.org>
Sat, 21 Aug 2010 08:44:49 +0000 (01:44 -0700)
committerDan Dennedy <dan@dennedy.org>
Sat, 21 Aug 2010 08:44:49 +0000 (01:44 -0700)
Previously, in a slideshow the luma filter would apply the dissolve or
wipe repeatedly over a slide. For example, with a slide duration of 75
frames and a luma period of 25 (expressed as 24), the wipe occurs 3
times. However, since the slides were static, you did not notice it
until the transition at the beginning of a new slide - when you do want
to see it. However, upon adding an affine filter to animate a smooth
pan/zoom, you do notice the extra repetitions - the slides appear to
blend with one another when they are not transitioning.

This change fixes that with new properties 'cycle' and 'duration'. Cycle
is basically a replacement for 'period' that fixes the semantics to
properly represent a duration. Where you would previously express, for
example, period=24, you now say cycle=25. The 'duration' property
prevents the repeating and expresses that the transition should only
occur within the first N frames of the cycle. See demo/mlt_slideshow2
for an example of using it in conjunction with the affine filter!

demo/mlt_slideshow2 [new file with mode: 0644]
src/modules/core/filter_luma.c

diff --git a/demo/mlt_slideshow2 b/demo/mlt_slideshow2
new file mode 100644 (file)
index 0000000..256e835
--- /dev/null
@@ -0,0 +1,8 @@
+melt \
+photos/.all.jpg ttl=75 \
+-attach crop center=1 \
+-attach affine  transition.cycle=225 transition.geometry="0=0,0:100%x100%;74=-100,-100:120%x120%;75=-60,-60:110%x110%;149=0:0:110%x110%;150=0,-60:110%x110%;224=-60,0:110%x110%" \
+-filter luma cycle=75 duration=25 \
+-track demo/music1.ogg \
+-transition mix \
+$*
index 04f52a2a8ec534e8d35be7caa0b9174eae188c3b..fc644a84c00b0d7e351362b358f2a67695e2284c 100644 (file)
@@ -23,6 +23,7 @@
 #include <framework/mlt_frame.h>
 #include <framework/mlt_producer.h>
 #include <framework/mlt_transition.h>
+#include <framework/mlt_log.h>
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -40,9 +41,14 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
        mlt_frame b_frame = mlt_properties_get_data( properties, "frame", NULL );
        mlt_properties b_frame_props = b_frame ? MLT_FRAME_PROPERTIES( b_frame ) : NULL;
        int out = mlt_properties_get_int( properties, "period" );
-       
-       if ( out == 0 )
-               out = 24;
+       int cycle = mlt_properties_get_int( properties, "cycle" );
+       int duration = mlt_properties_get_int( properties, "duration" );
+
+       out = out? out + 1 : 25;
+       if ( cycle )
+               out = cycle;
+       if ( duration < 1 || duration > out )
+               duration = out;
        *format = mlt_image_yuv422;
 
        if ( b_frame == NULL || mlt_properties_get_int( b_frame_props, "width" ) != *width || mlt_properties_get_int( b_frame_props, "height" ) != *height )
@@ -60,36 +66,18 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                {
                        mlt_properties luma_properties = MLT_TRANSITION_PROPERTIES( luma );
                        mlt_properties_set_int( luma_properties, "in", 0 );
-                       mlt_properties_set_int( luma_properties, "out", out );
+                       mlt_properties_set_int( luma_properties, "out", duration - 1 );
                        mlt_properties_set_int( luma_properties, "reverse", 1 );
                        mlt_properties_set_data( properties, "luma", luma, 0, ( mlt_destructor )mlt_transition_close, NULL );
                }
-
-               // Prime the filter with the first image to prevent a transition from the white
-               // of a test card.
-               error = mlt_frame_get_image( this, image, format, width, height, 1 );
-               if ( error == 0 )
-               {
-                       mlt_properties a_props = MLT_FRAME_PROPERTIES( this );
-                       int size = 0;
-                       uint8_t *src = mlt_properties_get_data( a_props, "image", &size );
-                       uint8_t *dst = mlt_pool_alloc( size );
-       
-                       if ( dst != NULL )
-                       {
-                               mlt_properties b_props = MLT_FRAME_PROPERTIES( b_frame );
-                               memcpy( dst, src, size );
-                               mlt_properties_set_data( b_props, "image", dst, size, mlt_pool_release, NULL );
-                               mlt_properties_set_int( b_props, "width", *width );
-                               mlt_properties_set_int( b_props, "height", *height );
-                               mlt_properties_set_int( b_props, "format", *format );
-                       }
-               }
        }
 
-       if ( luma != NULL && 
-               ( mlt_properties_get( properties, "blur" ) != NULL || 
-                 (int)mlt_frame_get_position( this ) % ( out + 1 ) != out ) )
+       mlt_position relative_pos = mlt_frame_get_position( this ) % out;
+       mlt_log_debug( MLT_FILTER_SERVICE(filter), "pos %d mod period %d\n", mlt_frame_get_position( this ),
+                                        relative_pos );
+       if ( luma != NULL &&
+            ( mlt_properties_get( properties, "blur" ) != NULL ||
+              ( mlt_frame_get_position( this ) >= duration && relative_pos < duration - 1 ) ) )
        {
                mlt_properties luma_properties = MLT_TRANSITION_PROPERTIES( luma );
                mlt_properties_pass( luma_properties, properties, "luma." );
@@ -98,7 +86,9 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
 
        error = mlt_frame_get_image( this, image, format, width, height, 1 );
 
-       if ( error == 0 )
+       // We only need a copy of the last frame in the cycle, but we could miss it
+       // with realtime frame-dropping, so we copy the last several frames of the cycle.
+       if ( error == 0 && relative_pos > out - duration )
        {
                mlt_properties a_props = MLT_FRAME_PROPERTIES( this );
                int size = 0;
@@ -107,6 +97,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
 
                if ( dst != NULL )
                {
+                       mlt_log_debug( MLT_FILTER_SERVICE(filter), "copying frame %d\n", relative_pos );
                        mlt_properties b_props = MLT_FRAME_PROPERTIES( b_frame );
                        memcpy( dst, src, size );
                        mlt_properties_set_data( b_props, "image", dst, size, mlt_pool_release, NULL );