producer_framebuffer.c: interpret negative speed as reverse
[melted] / src / modules / kdenlive / producer_framebuffer.c
index fa0ac0f..10dc22f 100644 (file)
@@ -194,7 +194,7 @@ static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index
 
 mlt_producer producer_framebuffer_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
 {
-
+       if ( !arg ) return NULL;
        mlt_producer this = NULL;
        this = calloc( 1, sizeof( struct mlt_producer_s ) );
        mlt_producer_init( this, NULL );
@@ -224,11 +224,11 @@ mlt_producer producer_framebuffer_init( mlt_profile profile, mlt_service_type ty
        
        if ( ptr )
        {
-               speed = atof( ++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';
+                       *ptr = '\0';
        }
                
        real_producer = mlt_factory_producer( profile, "fezzik", props );
@@ -236,7 +236,6 @@ mlt_producer producer_framebuffer_init( mlt_profile profile, mlt_service_type ty
 
        if (speed == 0.0) speed = 1.0;
 
-
        if ( this != NULL && real_producer != NULL)
        {
                // Get the properties of this producer
@@ -252,12 +251,18 @@ mlt_producer producer_framebuffer_init( mlt_profile profile, mlt_service_type ty
                // Grab some stuff from the real_producer
                mlt_properties_pass_list( properties, MLT_PRODUCER_PROPERTIES( real_producer ), "length, width,height" );
 
+               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 );
-                       mlt_properties_set_position( properties, "length", real_length / speed );
+                       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( this ) - 1 );
 
                // Since we control the seeking, prevent it from seeking on its own
                mlt_producer_set_speed( real_producer, 0 );