]> git.sesse.net Git - mlt/commitdiff
add support for ffmpeg libswscale
authorddennedy <ddennedy@d19143bc-622f-0410-bfdd-b5b2a6649095>
Sun, 4 Mar 2007 05:32:11 +0000 (05:32 +0000)
committerddennedy <ddennedy@d19143bc-622f-0410-bfdd-b5b2a6649095>
Sun, 4 Mar 2007 05:32:11 +0000 (05:32 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@955 d19143bc-622f-0410-bfdd-b5b2a6649095

ChangeLog
src/modules/avformat/Makefile
src/modules/avformat/configure
src/modules/avformat/consumer_avformat.c
src/modules/avformat/filter_avcolour_space.c
src/modules/avformat/producer_avformat.c

index 4e3830fcfff95a65d85d0529d2661faa5d3f236b..a28bfe016cda13320ceb1c997ce3c8ea88cfb8e9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2007-02-07 Dan Dennedy <dan@dennedy.org>
+       Added ffmpeg libswscale support to avformat module (requires configure
+       option --avformat-swscale)
+
 2006-12-07 Dan Dennedy <dan@dennedy.org
        Applied patch from Stephane Fillod to make configure run with bash
        since it uses bash-specific features. Also, patches headers to 
index b9e801adf188eba217a2a3a25a7cbccf34cc0987..d9ee317879eb0d60ca978e863c2f22aea5d95718 100644 (file)
@@ -19,6 +19,11 @@ LDFLAGS+=-L../../framework
 
 LDFLAGS+=-lavformat$(AVFORMAT_SUFFIX) -lavcodec$(AVFORMAT_SUFFIX) -lavutil$(AVFORMAT_SUFFIX) $(EXTRA_LIBS) -lmlt
 
+ifdef MMX_FLAGS
+       CFLAGS+=-DSWSCALE
+       LDFLAGS+=-lswscale$(AVFORMAT_SUFFIX)
+endif
+
 SRCS := $(OBJS:.o=.c)
 
 all:   $(TARGET)
index e3ad9d05728abbb0add8a7b36084ba7bae7b07e9..0d9986cfe8d949ac38d960d2639cc890475eaa1e 100755 (executable)
@@ -11,6 +11,7 @@ FFMPEG/avformat options:
   --avformat-static=path  - Link against a static ffmpeg dev tree
   --avformat-ldextra=libs - Provide additional libs to link with
   --avformat-suffix=suff  - Specify a custom suffix for an ffmpeg shared build
+  --avformat-swscale      - Use ffmpeg libswcale instead of img_convert
 
 EOF
 
@@ -44,6 +45,7 @@ else
        export extra_libs=
        export svn_ffmpeg=
        export avformat_suffix=
+       export swscale=false
 
        if [ "$shared_ffmpeg" != "" -a -f "$shared_ffmpeg" ]
        then
@@ -62,6 +64,7 @@ else
                        --avformat-svn )                svn_ffmpeg=true ;;
                        --avformat-cvs )                svn_ffmpeg=true ;;
                        --avformat-suffix=* )   avformat_suffix="${i#--avformat-suffix=}" ;;
+                       --avformat-swscale )    swscale=true ;;
                esac
        done
 
@@ -86,6 +89,7 @@ else
                        echo "LDFLAGS+=-L$static_ffmpeg/libavformat -L$static_ffmpeg/libavcodec -L$static_ffmpeg/libavutil" >> config.mak
                        [ $targetos = "Darwin" ] &&
                                echo "LDFLAGS+=-single_module" >> config.mak
+                       [ "$swscale" != "" ] && echo "SWSCALE=1" >> config.mak
                else
                        echo "avformat: Invalid path specified: $static_ffmpeg"
                        touch ../disable-avformat
@@ -96,6 +100,7 @@ else
                then
                        echo "CFLAGS+=-I$shared_ffmpeg/include/ffmpeg " >> config.mak
                        echo "LDFLAGS+=-L$shared_ffmpeg/$LIBDIR" >> config.mak
+                       [ "$swscale" != "" ] && echo "SWSCALE=1" >> config.mak
                else
                        echo "avformat: No build environment found. "
                        echo "          Try configuring mlt with --avformat-svn."
index 21242c665cbea2d123cd622e20f352d2f7108ddd..33487555d8028eba84d573c6230ab547ab1b5e06 100644 (file)
@@ -35,6 +35,9 @@
 
 // avformat header files
 #include <avformat.h>
+#ifdef SWSCALE
+#include <swscale.h>
+#endif
 
 //
 // This structure should be extended and made globally available in mlt
@@ -939,7 +942,15 @@ static void *consumer_thread( void *arg )
                                                }
 
                                                // Do the colour space conversion
+#ifdef SWSCALE
+                                               struct SwsContext *context = sws_getContext( width, height, PIX_FMT_YUV422,
+                                                       width, height, video_st->codec->pix_fmt, SWS_FAST_BILINEAR, NULL, NULL, NULL);
+                                               sws_scale( context, input->data, input->linesize, 0, height,
+                                                       output->data, output->linesize);
+                                               sws_freeContext( context );
+#else
                                                img_convert( ( AVPicture * )output, video_st->codec->pix_fmt, ( AVPicture * )input, PIX_FMT_YUV422, width, height );
+#endif
 
                                                // Apply the alpha if applicable
                                                if ( video_st->codec->pix_fmt == PIX_FMT_RGBA32 )
index 9ea2b8fee8e1894e9dbaba57666afd11072ceea7..976bb352b17e70eaa301b455c1e497ed66d4dd36 100644 (file)
@@ -24,6 +24,9 @@
 
 // ffmpeg Header files
 #include <avformat.h>
+#ifdef SWSCALE
+#include <swscale.h>
+#endif
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -67,9 +70,17 @@ static inline void convert_image( uint8_t *out, uint8_t *in, int out_fmt, int in
 {
        AVPicture input;
        AVPicture output;
-       avpicture_fill( &output, out, out_fmt, width, height );
        avpicture_fill( &input, in, in_fmt, width, height );
+       avpicture_fill( &output, out, out_fmt, width, height );
+#ifdef SWSCALE
+       struct SwsContext *context = sws_getContext( width, height, in_fmt,
+               width, height, out_fmt, SWS_FAST_BILINEAR, NULL, NULL, NULL);
+       sws_scale( context, input.data, input.linesize, 0, height,
+               output.data, output.linesize);
+       sws_freeContext( context );
+#else
        img_convert( &output, out_fmt, &input, in_fmt, width, height );
+#endif
 }
 
 /** Do it :-).
index 78c0d4849403376b3c04c63395d072ada361fb31..27478607a26370ce23a01a830d2f93989d572b5e 100644 (file)
@@ -26,6 +26,9 @@
 
 // ffmpeg Header files
 #include <avformat.h>
+#ifdef SWSCALE
+#include <swscale.h>
+#endif
 
 // System header files
 #include <stdlib.h>
@@ -374,6 +377,43 @@ static double producer_time_of_frame( mlt_producer this, mlt_position position )
 
 static inline void convert_image( AVFrame *frame, uint8_t *buffer, int pix_fmt, mlt_image_format format, int width, int height )
 {
+#ifdef SWSCALE
+       if ( format == mlt_image_yuv420p )
+       {
+               struct SwsContext *context = sws_getContext( width, height, pix_fmt,
+                       width, height, PIX_FMT_YUV420P, SWS_FAST_BILINEAR, NULL, NULL, NULL);
+               AVPicture output;
+               output.data[0] = buffer;
+               output.data[1] = buffer + width * height;
+               output.data[2] = buffer + ( 3 * width * height ) / 2;
+               output.linesize[0] = width;
+               output.linesize[1] = width >> 1;
+               output.linesize[2] = width >> 1;
+               sws_scale( context, frame->data, frame->linesize, 0, height,
+                       output.data, output.linesize);
+               sws_freeContext( context );
+       }
+       else if ( format == mlt_image_rgb24 )
+       {
+               struct SwsContext *context = sws_getContext( width, height, pix_fmt,
+                       width, height, PIX_FMT_RGB24, SWS_FAST_BILINEAR, NULL, NULL, NULL);
+               AVPicture output;
+               avpicture_fill( &output, buffer, PIX_FMT_RGB24, width, height );
+               sws_scale( context, frame->data, frame->linesize, 0, height,
+                       output.data, output.linesize);
+               sws_freeContext( context );
+       }
+       else
+       {
+               struct SwsContext *context = sws_getContext( width, height, pix_fmt,
+                       width, height, PIX_FMT_YUYV422, SWS_FAST_BILINEAR, NULL, NULL, NULL);
+               AVPicture output;
+               avpicture_fill( &output, buffer, PIX_FMT_YUYV422, width, height );
+               sws_scale( context, frame->data, frame->linesize, 0, height,
+                       output.data, output.linesize);
+               sws_freeContext( context );
+       }
+#else
        if ( format == mlt_image_yuv420p )
        {
                AVPicture pict;
@@ -397,6 +437,7 @@ static inline void convert_image( AVFrame *frame, uint8_t *buffer, int pix_fmt,
                avpicture_fill( &output, buffer, PIX_FMT_YUV422, width, height );
                img_convert( &output, PIX_FMT_YUV422, (AVPicture *)frame, pix_fmt, width, height );
        }
+#endif
 }
 
 /** Get an image from a frame.