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" );
+ int in = mlt_properties_get_position( properties, "in" );
// Determine the position
mlt_position first_position = (first_frame != NULL) ? mlt_frame_get_position( first_frame ) : -1;
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 );
+ double actual_position = in + prod_speed * (double) mlt_producer_position( producer );
if ( mlt_properties_get_int( properties, "reverse" ) )
actual_position = mlt_producer_get_playtime( producer ) - actual_position;
{
// Strobe effect wanted, calculate frame position
need_first = floor( actual_position );
- need_first -= need_first % strobe;
+ need_first -= MLT_POSITION_MOD(need_first, strobe);
}
if ( freeze )
{
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 );
uint8_t *first_alpha = mlt_properties_get_data( first_frame_properties, "alpha", NULL );
if ( !first_image )
{
- 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" ) );
int error = mlt_frame_get_image( first_frame, &first_image, format, width, height, writable );
if ( error != 0 ) {
- mlt_log_error( MLT_PRODUCER_SERVICE( producer ), "first_image == NULL get image died\n" );
+ mlt_log_warning( MLT_PRODUCER_SERVICE( producer ), "first_image == NULL get image died\n" );
+ mlt_properties_set_data( properties, "first_frame", NULL, 0, NULL, NULL );
mlt_service_unlock( MLT_PRODUCER_SERVICE( producer ) );
return error;
}
static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
{
- // Construct a new frame
- *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) );
- if( frame != NULL )
+ if ( frame )
{
+ // Construct a new frame
+ *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) );
+
// Stack the producer and producer's get image
mlt_frame_push_service( *frame, (void*) index );
mlt_frame_push_service( *frame, producer );
mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
mlt_properties frame_properties = MLT_FRAME_PROPERTIES(*frame);
+
+ // Get frame from the real producer
+ mlt_frame first_frame = mlt_properties_get_data( properties, "first_frame", NULL );
+
+ if ( first_frame == NULL )
+ {
+ // Get the frame to cache from the real producer
+ mlt_producer real_producer = mlt_properties_get_data( properties, "producer", NULL );
+
+ // Seek the producer to the correct place
+ mlt_producer_seek( real_producer, mlt_producer_position( producer ) );
+
+ // 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_inherit( frame_properties, MLT_FRAME_PROPERTIES(first_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" );
// Give the returned frame temporal identity
mlt_frame_set_position( *frame, mlt_producer_position( producer ) );
- 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_set_int( frame_properties, "meta.media.width", mlt_properties_get_int( properties, "width" ) );
+ mlt_properties_set_int( frame_properties, "meta.media.height", mlt_properties_get_int( properties, "height" ) );
mlt_properties_pass_list( frame_properties, properties, "width, height" );
}
if ( !arg ) return NULL;
mlt_producer producer = NULL;
producer = calloc( 1, sizeof( struct mlt_producer_s ) );
- mlt_producer_init( producer, NULL );
+ if ( !producer )
+ return NULL;
+
+ if ( mlt_producer_init( producer, NULL ) )
+ {
+ free( producer );
+ return NULL;
+ }
// Wrap loader
mlt_producer real_producer;
{
double real_length = ( (double) mlt_producer_get_length( real_producer ) ) / speed;
mlt_properties_set_position( properties, "length", real_length );
+ mlt_properties real_properties = MLT_PRODUCER_PROPERTIES( real_producer );
+ const char* service = mlt_properties_get( real_properties, "mlt_service" );
+ if ( service && !strcmp( service, "avformat" ) )
+ {
+ int n = mlt_properties_count( real_properties );
+ int i;
+ for ( i = 0; i < n; i++ )
+ {
+ if ( strstr( mlt_properties_get_name( real_properties, i ), "stream.frame_rate" ) )
+ {
+ double source_fps = mlt_properties_get_double( real_properties, mlt_properties_get_name( real_properties, i ) );
+ if ( source_fps > mlt_profile_fps( profile ) )
+ {
+ mlt_properties_set_double( real_properties, "force_fps", source_fps * speed );
+ mlt_properties_set_position( real_properties, "length", real_length );
+ mlt_properties_set_position( real_properties, "out", real_length - 1 );
+ speed = 1.0;
+ }
+ break;
+ }
+ }
+ }
}
mlt_properties_set_position( properties, "out", mlt_producer_get_length( producer ) - 1 );