]> git.sesse.net Git - mlt/commitdiff
Add resolution as init arg to libswscale filters.
authorDan Dennedy <dan@dennedy.org>
Sun, 28 Feb 2010 20:42:24 +0000 (12:42 -0800)
committerDan Dennedy <dan@dennedy.org>
Sun, 28 Feb 2010 20:42:24 +0000 (12:42 -0800)
src/modules/avformat/filter_avcolour_space.c
src/modules/avformat/filter_swscale.c
src/modules/core/producer_loader.c

index cc52483be9661ab64f8617c862d24c5a819e8e72..032fb4e40b42bb738e565972c76fc416c2d54fee 100644 (file)
@@ -163,6 +163,17 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
 
 mlt_filter filter_avcolour_space_init( void *arg )
 {
+       // Test to see if swscale accepts the arg as resolution
+       if ( arg )
+       {
+               int width = (int) arg;
+               struct SwsContext *context = sws_getContext( width, width, PIX_FMT_RGB32, 64, 64, PIX_FMT_RGB32, SWS_BILINEAR, NULL, NULL, NULL);
+               if ( context )
+                       sws_freeContext( context );
+               else
+                       return NULL;
+       }               
+
        mlt_filter this = mlt_filter_new( );
        if ( this != NULL )
                this->process = filter_process;
index a3ef5253330c8723aa73bfcf8709eeb772070fa4..f9c23e55792c3f7359492ec89df3c3e16b9f0762 100644 (file)
@@ -31,7 +31,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <assert.h>
 
 #if LIBAVUTIL_VERSION_INT < (50<<16)
 #define PIX_FMT_RGB32 PIX_FMT_RGBA32
@@ -124,46 +123,57 @@ static int filter_scale( mlt_frame this, uint8_t **image, mlt_image_format *form
        avpicture_fill( &output, outbuf, avformat, owidth, oheight );
 
        // Create the context and output image
+       owidth = owidth > 5120 ? 5120 : owidth;
        struct SwsContext *context = sws_getContext( iwidth, iheight, avformat, owidth, oheight, avformat, interp, NULL, NULL, NULL);
-       assert(context);
-
-       // Perform the scaling
-       sws_scale( context, input.data, input.linesize, 0, iheight, output.data, output.linesize);
-       sws_freeContext( context );
-
-       // Now update the frame
-       mlt_properties_set_data( properties, "image", output.data[0], owidth * ( oheight + 1 ) * bpp, ( mlt_destructor )mlt_pool_release, NULL );
-       mlt_properties_set_int( properties, "width", owidth );
-       mlt_properties_set_int( properties, "height", oheight );
-
-       // Return the output
-       *image = output.data[0];
-
-       // Scale the alpha channel only if exists and not correct size
-       int alpha_size = 0;
-       mlt_properties_get_data( properties, "alpha", &alpha_size );
-       if ( alpha_size > 0 && alpha_size != ( owidth * oheight ) )
+       if ( !context )
        {
-               // Create the context and output image
-               uint8_t *alpha = mlt_frame_get_alpha_mask( this );
-               if ( alpha )
+               owidth = owidth > 2048 ? 2048 : owidth;
+               context = sws_getContext( iwidth, iheight, avformat, owidth, oheight, avformat, interp, NULL, NULL, NULL);
+       }
+       if ( context )
+       {
+               // Perform the scaling
+               sws_scale( context, input.data, input.linesize, 0, iheight, output.data, output.linesize);
+               sws_freeContext( context );
+       
+               // Now update the frame
+               mlt_properties_set_data( properties, "image", output.data[0], owidth * ( oheight + 1 ) * bpp, ( mlt_destructor )mlt_pool_release, NULL );
+               mlt_properties_set_int( properties, "width", owidth );
+               mlt_properties_set_int( properties, "height", oheight );
+       
+               // Return the output
+               *image = output.data[0];
+       
+               // Scale the alpha channel only if exists and not correct size
+               int alpha_size = 0;
+               mlt_properties_get_data( properties, "alpha", &alpha_size );
+               if ( alpha_size > 0 && alpha_size != ( owidth * oheight ) )
                {
-                       avformat = PIX_FMT_GRAY8;
-                       struct SwsContext *context = sws_getContext( iwidth, iheight, avformat, owidth, oheight, avformat, interp, NULL, NULL, NULL);
-                       avpicture_fill( &input, alpha, avformat, iwidth, iheight );
-                       outbuf = mlt_pool_alloc( owidth * oheight );
-                       avpicture_fill( &output, outbuf, avformat, owidth, oheight );
-
-                       // Perform the scaling
-                       sws_scale( context, input.data, input.linesize, 0, iheight, output.data, output.linesize);
-                       sws_freeContext( context );
-
-                       // Set it back on the frame
-                       mlt_properties_set_data( MLT_FRAME_PROPERTIES( this ), "alpha", output.data[0], owidth * oheight, mlt_pool_release, NULL );
+                       // Create the context and output image
+                       uint8_t *alpha = mlt_frame_get_alpha_mask( this );
+                       if ( alpha )
+                       {
+                               avformat = PIX_FMT_GRAY8;
+                               struct SwsContext *context = sws_getContext( iwidth, iheight, avformat, owidth, oheight, avformat, interp, NULL, NULL, NULL);
+                               avpicture_fill( &input, alpha, avformat, iwidth, iheight );
+                               outbuf = mlt_pool_alloc( owidth * oheight );
+                               avpicture_fill( &output, outbuf, avformat, owidth, oheight );
+       
+                               // Perform the scaling
+                               sws_scale( context, input.data, input.linesize, 0, iheight, output.data, output.linesize);
+                               sws_freeContext( context );
+       
+                               // Set it back on the frame
+                               mlt_properties_set_data( MLT_FRAME_PROPERTIES( this ), "alpha", output.data[0], owidth * oheight, mlt_pool_release, NULL );
+                       }
                }
+       
+               return 0;
+       }
+       else
+       {
+               return 1;
        }
-
-       return 0;
 }
 
 /** Constructor for the filter.
@@ -171,9 +181,20 @@ static int filter_scale( mlt_frame this, uint8_t **image, mlt_image_format *form
 
 mlt_filter filter_swscale_init( mlt_profile profile, void *arg )
 {
-       // Create a new scaler
-       mlt_filter this = mlt_factory_filter( profile, "rescale", arg );
+       // Test to see if swscale accepts the arg as resolution
+       if ( arg )
+       {
+               int width = (int) arg;
+               struct SwsContext *context = sws_getContext( width, width, PIX_FMT_RGB32, 64, 64, PIX_FMT_RGB32, SWS_BILINEAR, NULL, NULL, NULL);
+               if ( context )
+                       sws_freeContext( context );
+               else
+                       return NULL;
+       }               
 
+       // Create a new scaler
+       mlt_filter this = mlt_factory_filter( profile, "rescale", NULL );
+       
        // If successful, then initialise it
        if ( this != NULL )
        {
@@ -181,7 +202,7 @@ mlt_filter filter_swscale_init( mlt_profile profile, void *arg )
                mlt_properties properties = MLT_FILTER_PROPERTIES( this );
 
                // Set the inerpolation
-               mlt_properties_set( properties, "interpolation", arg == NULL ? "bilinear" : arg );
+               mlt_properties_set( properties, "interpolation", "bilinear" );
 
                // Set the method
                mlt_properties_set_data( properties, "method", filter_scale, 0, NULL, NULL );
index 4d1c4afccecc02fcf5999d8f537c1f3a794da382..424951972bfb0d2b2ff3c16efd20c7ea2e3f1ac5 100644 (file)
@@ -106,17 +106,15 @@ static mlt_producer create_producer( mlt_profile profile, char *file )
 
 static void create_filter( mlt_profile profile, mlt_producer producer, char *effect, int *created )
 {
-       // The swscale filter can not handle images with a width > 2048 and the
-       // sdl_image producer does not scale on its own
-       if ( strncmp( effect, "swscale", 7 ) == 0 &&
-            mlt_properties_get_int( MLT_PRODUCER_PROPERTIES( producer ), "_real_width" ) > 2048 &&
-            strcmp( mlt_properties_get( MLT_PRODUCER_PROPERTIES( producer ), "mlt_service" ), "sdl_image" ) == 0 )
-               return;
-
        char *id = strdup( effect );
        char *arg = strchr( id, ':' );
        if ( arg != NULL )
                *arg ++ = '\0';
+
+       // The swscale and avcolor_space filters require resolution as arg to test compatibility
+       if ( strncmp( effect, "swscale", 7 ) == 0 || strncmp( effect, "avcolo", 6 ) == 0 )
+               arg = (char*) mlt_properties_get_int( MLT_PRODUCER_PROPERTIES( producer ), "_real_width" );
+
        mlt_filter filter = mlt_factory_filter( profile, id, arg );
        if ( filter != NULL )
        {