]> git.sesse.net Git - mlt/blobdiff - src/modules/xine/filter_deinterlace.c
make mlt_position type double
[mlt] / src / modules / xine / filter_deinterlace.c
index 8c7cf003e6cd4036ba80b878d39f309b82fa9ed0..70457e96dcc084eb2863f30d52f5f1d2972bc6f1 100644 (file)
@@ -111,7 +111,7 @@ static int deinterlace_yadif( mlt_frame frame, mlt_filter filter, uint8_t **imag
        int next_width = *width;
        int next_height = *height;
        
-       mlt_log_debug( MLT_FILTER_SERVICE(filter), "previous %d current %d next %d\n",
+       mlt_log_debug( MLT_FILTER_SERVICE(filter), "previous " MLT_POSITION_FMT " current " MLT_POSITION_FMT " next " MLT_POSITION_FMT "\n",
                previous_frame? mlt_frame_original_position(previous_frame) : -1,
                mlt_frame_original_position(frame),
                next_frame?  mlt_frame_original_position(next_frame) : -1);
@@ -119,15 +119,6 @@ static int deinterlace_yadif( mlt_frame frame, mlt_filter filter, uint8_t **imag
        if ( !previous_frame || !next_frame )
                return 1;
 
-       // Some producers like pixbuf want rescale_width & _height, but will not get them if you request
-       // the previous image first. So, on the first iteration, we make the previous frame the same
-       // as the current frame.
-       if ( !mlt_properties_get_int( MLT_FILTER_PROPERTIES(filter), "_notfirst" ) )
-       {
-               previous_frame = frame;
-               mlt_properties_set_int( MLT_FILTER_PROPERTIES(filter), "_notfirst", 1 );
-       }
-
        // Get the preceding frame's image
        int error = mlt_frame_get_image( previous_frame, &previous_image, format, &previous_width, &previous_height, 0 );
        int progressive = mlt_properties_get_int( MLT_FRAME_PROPERTIES( previous_frame ), "progressive" );
@@ -204,7 +195,7 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
        // At this point - before image was requested - (progressive == 0) cannot be trusted because
        // some producers (avformat) do not yet know.
 
-       if ( deinterlace )
+       if ( deinterlace && !mlt_properties_get_int( properties, "test_image" ) )
        {
                // Determine deinterlace method
                char *method_str = mlt_properties_get( MLT_FILTER_PROPERTIES( filter ), "method" );
@@ -229,6 +220,16 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                else if ( strcmp( method_str, "greedy" ) == 0 )
                        method = DEINTERLACE_GREEDY;
 
+               // Some producers like pixbuf want rescale_width & _height, but will not get them if you request
+               // the previous image first. So, on the first iteration, we use linearblend.
+               if ( ( method == DEINTERLACE_YADIF || method == DEINTERLACE_YADIF_NOSPATIAL ) &&
+                       !mlt_properties_get_int( MLT_FILTER_PROPERTIES(filter), "_notfirst" ) )
+               {
+                       mlt_properties_set_int( MLT_FILTER_PROPERTIES(filter), "_notfirst", 1 );
+                       method = DEINTERLACE_LINEARBLEND;
+                       error = 1;
+               }
+
                if ( method == DEINTERLACE_YADIF )
                {
                        error = deinterlace_yadif( frame, filter, image, format, width, height, YADIF_MODE_TEMPORAL_SPATIAL );
@@ -239,16 +240,27 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                }
                if ( error || ( method > DEINTERLACE_NONE && method < DEINTERLACE_YADIF ) )
                {
-                       // Signal that we no longer need previous and next frames
                        mlt_service service = mlt_properties_get_data( MLT_FILTER_PROPERTIES(filter), "service", NULL );
-                       mlt_properties_set_int( MLT_SERVICE_PROPERTIES(service), "_need_previous_next", 0 );
-                       
-                       if ( error )
-                               method = DEINTERLACE_ONEFIELD;
-                       
+
                        // Get the current frame's image
-                       error = mlt_frame_get_image( frame, image, format, width, height, writable );
+                       int error2 = mlt_frame_get_image( frame, image, format, width, height, writable );
                        progressive = mlt_properties_get_int( properties, "progressive" );
+
+                       if ( error )
+                       {
+                               method = DEINTERLACE_LINEARBLEND;
+                               // If YADIF requested, prev/next cancelled because some previous frames were progressive,
+                               // but new frames are interlaced, then turn prev/next frames back on.
+                               if ( !progressive )
+                                       mlt_properties_set_int( MLT_SERVICE_PROPERTIES(service), "_need_previous_next", 1 );
+                       }
+                       else
+                       {
+                               // Signal that we no longer need previous and next frames
+                               mlt_properties_set_int( MLT_SERVICE_PROPERTIES(service), "_need_previous_next", 0 );
+                       }
+                       error = error2;
+                       
                        if ( !error && !progressive )
                        {
                                // OK, now we know we have work to do and can request the image in our format