// Get the filter object and properties
mlt_producer producer = mlt_frame_pop_service( this );
- mlt_frame first_frame = mlt_frame_pop_service( this );
+ int index = ( int )mlt_frame_pop_service( this );
+ mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
- mlt_properties producer_properties = MLT_PRODUCER_PROPERTIES( producer );
+ mlt_service_lock( MLT_PRODUCER_SERVICE( producer ) );
// Frame properties objects
mlt_properties frame_properties = MLT_FRAME_PROPERTIES( this );
- mlt_properties first_frame_properties = MLT_FRAME_PROPERTIES( first_frame );
+ mlt_frame first_frame = mlt_properties_get_data( properties, "first_frame", NULL );
+
+ // Get producer parameters
+ int strobe = mlt_properties_get_int( properties, "strobe" );
+ int freeze = mlt_properties_get_int( properties, "freeze" );
+ int freeze_after = mlt_properties_get_int( properties, "freeze_after" );
+ int freeze_before = mlt_properties_get_int( properties, "freeze_before" );
+
+ // Determine the position
+ mlt_position first_position = (first_frame != NULL) ? mlt_frame_get_position( first_frame ) : -1;
+ mlt_position need_first = freeze;
+
+ if ( !freeze || freeze_after || freeze_before )
+ {
+ double prod_speed = mlt_properties_get_double( properties, "_speed" );
+ double actual_position = prod_speed * (double) mlt_producer_position( producer );
+
+ if ( mlt_properties_get_int( properties, "reverse" ) )
+ actual_position = mlt_producer_get_playtime( producer ) - actual_position;
+ if ( strobe < 2 )
+ {
+ need_first = floor( actual_position );
+ }
+ else
+ {
+ // Strobe effect wanted, calculate frame position
+ need_first = floor( actual_position );
+ need_first -= need_first % strobe;
+ }
+ if ( freeze )
+ {
+ if ( freeze_after && need_first > freeze ) need_first = freeze;
+ else if ( freeze_before && need_first < freeze ) need_first = freeze;
+ }
+ }
+
+ // Determine output buffer size
*width = mlt_properties_get_int( frame_properties, "width" );
*height = mlt_properties_get_int( frame_properties, "height" );
-
+
int size;
switch ( *format )
{
case mlt_image_rgb24:
size = *width * ( *height + 1 ) * 3;
break;
+ case mlt_image_rgb24a:
+ case mlt_image_opengl:
+ size = *width * ( *height + 1 ) * 4;
+ break;
default:
*format = mlt_image_yuv422;
size = *width * ( *height + 1 ) * 2;
break;
}
+
- uint8_t *output = mlt_properties_get_data( producer_properties, "output_buffer", NULL );
+ // Get output buffer
+ int buffersize = 0;
+ uint8_t *output = mlt_properties_get_data( properties, "output_buffer", &buffersize );
+ if( buffersize == 0 || buffersize != size)
+ {
+ // invalidate cached frame
+ first_position = -1;
+ }
- if( output == NULL )
+ if ( need_first != first_position )
{
- output = mlt_pool_alloc( size );
+ // invalidate cached frame
+ first_position = -1;
+
+ // Bust the cached frame
+ mlt_properties_set_data( properties, "first_frame", NULL, 0, NULL, NULL );
+ first_frame = NULL;
+ }
- // Let someone else clean up
- mlt_properties_set_data( producer_properties, "output_buffer", output, size, mlt_pool_release, NULL );
+ if (output != NULL && first_position != -1) {
+ // Using the cached frame
+ uint8_t *image_copy = mlt_pool_alloc( size );
+ memcpy( image_copy, output, size );
+
+ // Set the output image
+ *image = image_copy;
+ mlt_properties_set_data( frame_properties, "image", image_copy, size, ( mlt_destructor )mlt_pool_release, NULL );
+
+ *width = mlt_properties_get_int( properties, "_output_width" );
+ *height = mlt_properties_get_int( properties, "_output_height" );
+ *format = mlt_properties_get_int( properties, "_output_format" );
+
+ return 0;
}
- uint8_t *first_image = mlt_properties_get_data( first_frame_properties, "image", NULL );
+ // Get the cached frame
+ if ( first_frame == NULL )
+ {
+ // Get the frame to cache from the real producer
+ mlt_producer real_producer = mlt_properties_get_data( properties, "producer", NULL );
- // which frames are buffered?
+ // Seek the producer to the correct place
+ mlt_producer_seek( real_producer, need_first );
- int error = 0;
+ // Get the frame
+ mlt_service_get_frame( MLT_PRODUCER_SERVICE( real_producer ), &first_frame, index );
+ // Cache the frame
+ mlt_properties_set_data( properties, "first_frame", first_frame, 0, ( mlt_destructor )mlt_frame_close, NULL );
+ }
+ mlt_properties first_frame_properties = MLT_FRAME_PROPERTIES( first_frame );
+
+
+ // Which frames are buffered?
+ uint8_t *first_image = mlt_properties_get_data( first_frame_properties, "image", NULL );
if( first_image == NULL )
{
- mlt_properties props = MLT_FRAME_PROPERTIES( this );
- mlt_properties test_properties = MLT_FRAME_PROPERTIES( first_frame );
- mlt_properties_set_double( test_properties, "consumer_aspect_ratio", mlt_properties_get_double( props, "consumer_aspect_ratio" ) );
- mlt_properties_set( test_properties, "rescale.interp", mlt_properties_get( props, "rescale.interp" ) );
+ mlt_properties_set_double( first_frame_properties, "consumer_aspect_ratio", mlt_properties_get_double( frame_properties, "consumer_aspect_ratio" ) );
+ mlt_properties_set( first_frame_properties, "rescale.interp", mlt_properties_get( frame_properties, "rescale.interp" ) );
- error = mlt_frame_get_image( first_frame, &first_image, format, width, height, writable );
+ int error = mlt_frame_get_image( first_frame, &first_image, format, width, height, writable );
- if( error != 0 ) {
+ if ( error != 0 ) {
fprintf(stderr, "first_image == NULL get image died\n");
return error;
}
+ output = mlt_pool_alloc( size );
+ memcpy( output, first_image, size );
+ // Let someone else clean up
+ mlt_properties_set_data( properties, "output_buffer", output, size, mlt_pool_release, NULL );
+ mlt_properties_set_int( properties, "_output_width", *width );
+ mlt_properties_set_int( properties, "_output_height", *height );
+ mlt_properties_set_int( properties, "_output_format", *format );
+
}
+ mlt_service_unlock( MLT_PRODUCER_SERVICE( producer ) );
- // Start with a base image
- memcpy( output, first_image, size );
+ // Create a copy
+ uint8_t *image_copy = mlt_pool_alloc( size );
+ memcpy( image_copy, first_image, size );
- *image = output;
- mlt_properties_set_data( frame_properties, "image", output, size, NULL, NULL );
-
- // Make sure that no further scaling is done
- mlt_properties_set( frame_properties, "rescale.interps", "none" );
- mlt_properties_set( frame_properties, "scale", "off" );
-
- mlt_frame_close( first_frame );
+ // Set the output image
+ *image = image_copy;
+ mlt_properties_set_data( frame_properties, "image", *image, size, ( mlt_destructor )mlt_pool_release, NULL );
return 0;
}
{
// Construct a new frame
*frame = mlt_frame_init( MLT_PRODUCER_SERVICE( this ) );
- mlt_properties properties = MLT_PRODUCER_PROPERTIES( this );
-
if( frame != NULL )
{
- mlt_frame first_frame = mlt_properties_get_data( properties, "first_frame", NULL );
-
- mlt_position first_position = (first_frame != NULL) ? mlt_frame_get_position( first_frame ) : -1;
-
- // Get the real producer
- mlt_producer real_producer = mlt_properties_get_data( properties, "producer", NULL );
-
- // get properties
- int strobe = mlt_properties_get_int( properties, "strobe");
- int freeze = mlt_properties_get_int( properties, "freeze");
- int freeze_after = mlt_properties_get_int( properties, "freeze_after");
- int freeze_before = mlt_properties_get_int( properties, "freeze_before");
-
- mlt_position need_first;
-
- if (!freeze || freeze_after || freeze_before) {
- double prod_speed = mlt_properties_get_double( properties, "_speed");
- double actual_position = prod_speed * (double) mlt_producer_position( this );
-
- if (mlt_properties_get_int( properties, "reverse")) actual_position = mlt_producer_get_playtime(this) - actual_position;
-
- if (strobe < 2)
- {
- need_first = floor( actual_position );
- }
- else
- {
- // Strobe effect wanted, calculate frame position
- need_first = floor( actual_position );
- need_first -= need_first%strobe;
- }
- if (freeze)
- {
- if (freeze_after && need_first > freeze) need_first = freeze;
- else if (freeze_before && need_first < freeze) need_first = freeze;
- }
- }
- else need_first = freeze;
-
- if( need_first != first_position )
- {
- mlt_frame_close( first_frame );
- first_position = -1;
- first_frame = NULL;
- }
-
- if( first_frame == NULL )
- {
- // Seek the producer to the correct place
- mlt_producer_seek( real_producer, need_first );
-
- // Get the frame
- mlt_service_get_frame( MLT_PRODUCER_SERVICE( real_producer ), &first_frame, index );
- }
-
- // Make sure things are in their place
- mlt_properties_set_data( properties, "first_frame", first_frame, 0, NULL, NULL );
-
// Stack the producer and producer's get image
- mlt_frame_push_service( *frame, first_frame );
- mlt_properties_inc_ref( MLT_FRAME_PROPERTIES( first_frame ) );
-
+ mlt_frame_push_service( *frame, (void*) index );
mlt_frame_push_service( *frame, this );
mlt_frame_push_service( *frame, framebuffer_get_image );
-
+ mlt_properties properties = MLT_PRODUCER_PROPERTIES( this );
+ mlt_properties frame_properties = MLT_FRAME_PROPERTIES(*frame);
+
+ double force_aspect_ratio = mlt_properties_get_double( properties, "force_aspect_ratio" );
+ if ( force_aspect_ratio <= 0.0 ) force_aspect_ratio = mlt_properties_get_double( properties, "aspect_ratio" );
+ mlt_properties_set_double( frame_properties, "aspect_ratio", force_aspect_ratio );
+
// Give the returned frame temporal identity
mlt_frame_set_position( *frame, mlt_producer_position( this ) );
+
+ mlt_properties_set_int( frame_properties, "real_width", mlt_properties_get_int( properties, "width" ) );
+ mlt_properties_set_int( frame_properties, "real_height", mlt_properties_get_int( properties, "height" ) );
+ mlt_properties_pass_list( frame_properties, properties, "width, height" );
}
return 0;
this = calloc( 1, sizeof( struct mlt_producer_s ) );
mlt_producer_init( this, NULL );
- // Wrap fezzik
+ // 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%:
- inigo framebuffer:my_video.mpg?0.5
+ 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.
*ptr = '\0';
}
- real_producer = mlt_factory_producer( profile, "fezzik", props );
+ real_producer = mlt_factory_producer( profile, "abnormal", props );
free( props );
if (speed == 0.0) speed = 1.0;
// Get the properties of this producer
mlt_properties properties = MLT_PRODUCER_PROPERTIES( this );
- // Fezzik normalised it for us already
- mlt_properties_set_int( properties, "fezzik_normalised", 1);
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" );
+ mlt_properties_pass_list( properties, MLT_PRODUCER_PROPERTIES( real_producer ), "length, width, height, aspect_ratio" );
if ( speed < 0 )
{