Hi, Following a feature request in Kdenlive (1), I tried to make a few changes to the motion_est filter to allow the detection of scene changes in a clip.
I made 2 changes to the filter: 1 - add a geometry property "bounding" allowing to process filter on a part of the image only to speed up processing 2 - Store the scene changes frame positions in a "_scene_cut" property that can later be retrieved by the application Patch below, are you ok with this approach? (1) http://kdenlive.org/mantis/view.php?id=683 regards jb _________________________________________________________________________________ diff --git a/src/modules/motion_est/filter_motion_est.c b/src/modules/motion_est/filter_motion_est.c index d2dff28..7bdf353 100644 --- a/src/modules/motion_est/filter_motion_est.c +++ b/src/modules/motion_est/filter_motion_est.c @@ -890,6 +890,22 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format /* Check to see if somebody else has given us bounds */ struct mlt_geometry_item_s *bounds = mlt_properties_get_data( MLT_FRAME_PROPERTIES( frame ), "bounds", NULL ); + + if (bounds == NULL ) + { + char *property = mlt_properties_get( MLT_FILTER_PROPERTIES( filter ), "bounding" ); + if ( property != NULL ) + { + mlt_geometry geometry = mlt_geometry_init( ); + mlt_profile profile = mlt_service_profile( MLT_FILTER_SERVICE( filter ) ); + mlt_geometry_parse( geometry, property, 0, profile->width, profile- >height ); + struct mlt_geometry_item_s item; + if ( geometry != NULL ) { + mlt_geometry_fetch( geometry, &item, 0 ); + bounds = &item; + } + } + } if( bounds != NULL ) { // translate pixel units (from bounds) to macroblock units @@ -935,7 +951,24 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format if( c->comparison_average > 10 * c->mb_w * c->mb_h && c->comparison_average > c->previous_msad * 2 ) { - fprintf(stderr, " - SAD: %d <<Shot change>>\n", c- >comparison_average); + //fprintf(stderr, " - SAD: %d <<Shot change>>\n", c->comparison_average ); + mlt_properties properties = mlt_filter_properties( filter ); + mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "shot_change", 1 ); + char *cuts = mlt_properties_get( properties, "_scene_cuts" ); + if ( cuts ) { + char *newcuts; + char current_position[sizeof( int32_t ) + sizeof( char ) + 1]; + snprintf( current_position, sizeof( current_position ), ":%d", c- >current_frame_position ); + newcuts = current_position; + char *result = malloc( strlen( cuts ) + strlen( newcuts ) + 1 ); + if ( result != NULL ) + { + strcpy( result, cuts ); + strcat( result, newcuts ); + mlt_properties_set( properties, "_scene_cuts", result ); + free( result ); + } + } mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "shot_change", 1); // c->former_vectors_valid = 0; // Invalidate the previous frame's predictors c->shot_change = 1; @@ -1055,7 +1088,6 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format static mlt_frame filter_process( mlt_filter this, mlt_frame frame ) { - // Keeps tabs on the filter object mlt_frame_push_service( frame, this); ------------------------------------------------------------------------------ Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://p.sf.net/sfu/appdyn_sfd2d_oct _______________________________________________ Mlt-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mlt-devel
