From 87ddb143a7f56e31c860d37631fb26f9821d3e48 Mon Sep 17 00:00:00 2001 From: lilo_booter Date: Thu, 7 Oct 2004 18:48:52 +0000 Subject: [PATCH] Revised attached filter handling and clones git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@467 d19143bc-622f-0410-bfdd-b5b2a6649095 --- src/framework/mlt_filter.c | 4 --- src/framework/mlt_producer.c | 46 +++++++++++++++++++----- src/framework/mlt_service.c | 17 --------- src/framework/mlt_tractor.c | 3 -- src/modules/avformat/consumer_avformat.c | 10 +++--- src/modules/core/filter_data_show.c | 2 +- src/modules/core/filter_watermark.c | 2 +- src/modules/plus/filter_affine.c | 2 +- 8 files changed, 47 insertions(+), 39 deletions(-) diff --git a/src/framework/mlt_filter.c b/src/framework/mlt_filter.c index ccdf45da..37f91db3 100644 --- a/src/framework/mlt_filter.c +++ b/src/framework/mlt_filter.c @@ -176,11 +176,7 @@ static int filter_get_frame( mlt_service service, mlt_frame_ptr frame, int index { mlt_position position = mlt_frame_get_position( *frame ); if ( position >= in && ( out == 0 || position <= out ) ) - { - mlt_frame_set_position( *frame, position - in ); *frame = mlt_filter_process( this, *frame ); - mlt_frame_set_position( *frame, position + in ); - } return 0; } else diff --git a/src/framework/mlt_producer.c b/src/framework/mlt_producer.c index ddcda285..f29f4c58 100644 --- a/src/framework/mlt_producer.c +++ b/src/framework/mlt_producer.c @@ -397,9 +397,21 @@ static int producer_get_frame( mlt_service service, mlt_frame_ptr frame, int ind if ( !mlt_producer_is_cut( this ) ) { + // Get the properties of this producer + mlt_properties properties = mlt_producer_properties( this ); + // Determine eof handling char *eof = mlt_properties_get( mlt_producer_properties( this ), "eof" ); + // Get the speed of the producer + double speed = mlt_producer_get_speed( this ); + + // We need to use the clone if it's specified + mlt_producer clone = mlt_properties_get_data( properties, "use_clone", NULL ); + + // If no clone is specified, use this + clone = clone == NULL ? this : clone; + // A properly instatiated producer will have a get_frame method... if ( this->get_frame == NULL || ( !strcmp( eof, "continue" ) && mlt_producer_position( this ) > mlt_producer_get_out( this ) ) ) { @@ -419,12 +431,11 @@ static int producer_get_frame( mlt_service service, mlt_frame_ptr frame, int ind else { // Get the frame from the implementation - result = this->get_frame( this, frame, index ); + result = this->get_frame( clone, frame, index ); } // Copy the fps and speed of the producer onto the frame - mlt_properties properties = mlt_frame_properties( *frame ); - double speed = mlt_producer_get_speed( this ); + properties = mlt_frame_properties( *frame ); mlt_properties_set_double( properties, "_speed", speed ); mlt_properties_set_double( properties, "fps", mlt_producer_get_fps( this ) ); mlt_properties_set_int( properties, "test_audio", mlt_frame_is_test_audio( *frame ) ); @@ -434,9 +445,21 @@ static int producer_get_frame( mlt_service service, mlt_frame_ptr frame, int ind } else { + // Get the parent of this cut + mlt_producer parent = mlt_producer_cut_parent( this ); + + // Get the properties of the parent + mlt_properties parent_properties = mlt_producer_properties( parent ); + + // Get the properties of the cut mlt_properties properties = mlt_producer_properties( this ); + + // Determine the clone index int clone_index = mlt_properties_get_int( properties, "_clone" ); + + // Determine the clone to use mlt_producer clone = this; + if ( clone_index > 0 ) { char key[ 25 ]; @@ -447,13 +470,20 @@ static int producer_get_frame( mlt_service service, mlt_frame_ptr frame, int ind } else { - clone = mlt_producer_cut_parent( this ); + clone = parent; } + + // We need to seek to the correct position in the clone mlt_producer_seek( clone, mlt_producer_get_in( this ) + mlt_properties_get_int( properties, "_position" ) ); - result = producer_get_frame( mlt_producer_service( clone ), frame, index ); - double speed = mlt_producer_get_speed( this ); - mlt_properties_set_double( mlt_frame_properties( *frame ), "_speed", speed ); - mlt_producer_prepare_next( clone ); + + // Assign the clone property to the parent + mlt_properties_set_data( parent_properties, "use_clone", clone, 0, NULL, NULL ); + + // Now get the frame from the parents service + result = mlt_service_get_frame( mlt_producer_service( parent ), frame, index ); + + // We're done with the clone now + mlt_properties_set_data( parent_properties, "use_clone", NULL, 0, NULL, NULL ); } return result; diff --git a/src/framework/mlt_service.c b/src/framework/mlt_service.c index 9a1cc376..df416f0d 100644 --- a/src/framework/mlt_service.c +++ b/src/framework/mlt_service.c @@ -308,14 +308,6 @@ void mlt_service_apply_filters( mlt_service this, mlt_frame frame, int index ) mlt_position this_in = mlt_properties_get_position( service_properties, "in" ); mlt_position this_out = mlt_properties_get_position( service_properties, "out" ); - // Hmm - special case for cuts - apply filters from the parent first - if ( mlt_properties_get_int( service_properties, "_cut" ) ) - { - mlt_service_apply_filters( ( mlt_service )mlt_properties_get_data( service_properties, "_cut_parent", NULL ), frame, 0 ); - position -= this_in; - mlt_frame_set_position( frame, position ); - } - if ( index == 0 || mlt_properties_get_int( service_properties, "_filter_private" ) == 0 ) { // Process the frame with the attached filters @@ -329,21 +321,12 @@ void mlt_service_apply_filters( mlt_service this, mlt_frame frame, int index ) { mlt_properties_set_position( frame_properties, "in", 0 ); mlt_properties_set_position( frame_properties, "out", out == 0 ? this_out - this_in : out - in ); - mlt_frame_set_position( frame, position - in ); mlt_filter_process( base->filters[ i ], frame ); mlt_service_apply_filters( mlt_filter_service( base->filters[ i ] ), frame, index + 1 ); - mlt_frame_set_position( frame, position + in ); } } } } - - if ( mlt_properties_get_int( service_properties, "_cut" ) ) - { - mlt_properties_set_position( frame_properties, "in", this_in ); - mlt_properties_set_position( frame_properties, "out", this_out ); - mlt_frame_set_position( frame, position + this_in ); - } } /** Obtain a frame. diff --git a/src/framework/mlt_tractor.c b/src/framework/mlt_tractor.c index 537e4c88..92a10dc9 100644 --- a/src/framework/mlt_tractor.c +++ b/src/framework/mlt_tractor.c @@ -328,10 +328,8 @@ static int producer_get_frame( mlt_producer parent, mlt_frame_ptr frame, int tra // Now stack callbacks if ( audio != NULL ) { - mlt_properties audio_properties = mlt_frame_properties( audio ); mlt_frame_push_audio( *frame, audio ); ( *frame )->get_audio = producer_get_audio; - mlt_properties_set_position( frame_properties, "_position", mlt_properties_get_position( audio_properties, "_position" ) ); } if ( video != NULL ) @@ -343,7 +341,6 @@ static int producer_get_frame( mlt_producer parent, mlt_frame_ptr frame, int tra mlt_properties_set_int( frame_properties, "width", mlt_properties_get_int( video_properties, "width" ) ); mlt_properties_set_int( frame_properties, "height", mlt_properties_get_int( video_properties, "height" ) ); mlt_properties_set_double( frame_properties, "aspect_ratio", mlt_properties_get_double( video_properties, "aspect_ratio" ) ); - mlt_properties_set_position( frame_properties, "_position", mlt_properties_get_position( video_properties, "_position" ) ); } mlt_frame_set_position( *frame, mlt_producer_frame( parent ) ); diff --git a/src/modules/avformat/consumer_avformat.c b/src/modules/avformat/consumer_avformat.c index 6bb672a1..318aec6b 100644 --- a/src/modules/avformat/consumer_avformat.c +++ b/src/modules/avformat/consumer_avformat.c @@ -819,12 +819,13 @@ static void *consumer_thread( void *arg ) pkt.size = avcodec_encode_audio( c, audio_outbuf, audio_outbuf_size, buffer ); // Write the compressed frame in the media file - pkt.pts= c->coded_frame->pts; + if ( c->coded_frame ) + pkt.pts= c->coded_frame->pts; pkt.flags |= PKT_FLAG_KEY; pkt.stream_index= audio_st->index; pkt.data= audio_outbuf; - if ( av_write_frame( oc, &pkt ) != 0) + if ( av_interleaved_write_frame( oc, &pkt ) != 0) fprintf(stderr, "Error while writing audio frame\n"); } else @@ -897,7 +898,8 @@ static void *consumer_thread( void *arg ) AVPacket pkt; av_init_packet( &pkt ); - pkt.pts= c->coded_frame->pts; + if ( c->coded_frame ) + pkt.pts= c->coded_frame->pts; if(c->coded_frame->key_frame) pkt.flags |= PKT_FLAG_KEY; pkt.stream_index= video_st->index; @@ -905,7 +907,7 @@ static void *consumer_thread( void *arg ) pkt.size= out_size; // write the compressed frame in the media file - ret = av_write_frame(oc, &pkt); + ret = av_interleaved_write_frame(oc, &pkt); } } frame_count++; diff --git a/src/modules/core/filter_data_show.c b/src/modules/core/filter_data_show.c index 2843ddee..6323236b 100644 --- a/src/modules/core/filter_data_show.c +++ b/src/modules/core/filter_data_show.c @@ -150,7 +150,7 @@ static int process_feed( mlt_properties feed, mlt_filter filter, mlt_frame frame } // Set the original position on the frame - mlt_frame_set_position( frame, mlt_properties_get_int( feed, "position" ) ); + mlt_frame_set_position( frame, mlt_properties_get_int( feed, "position" ) - mlt_properties_get_int( feed, "in" ) ); // Process the filter mlt_filter_process( requested, frame ); diff --git a/src/modules/core/filter_watermark.c b/src/modules/core/filter_watermark.c index 4908d441..e91aeadd 100644 --- a/src/modules/core/filter_watermark.c +++ b/src/modules/core/filter_watermark.c @@ -193,7 +193,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 ); diff --git a/src/modules/plus/filter_affine.c b/src/modules/plus/filter_affine.c index 2e76c51c..f3d0b6bb 100644 --- a/src/modules/plus/filter_affine.c +++ b/src/modules/plus/filter_affine.c @@ -96,7 +96,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 frame filter mlt_frame_push_service( frame, this ); -- 2.39.2