From: ddennedy Date: Sun, 4 Mar 2007 05:32:11 +0000 (+0000) Subject: add support for ffmpeg libswscale X-Git-Url: http://research.m1stereo.tv/gitweb?a=commitdiff_plain;h=cef70011d08af33924ab3b97d628deefce47b953;p=melted add support for ffmpeg libswscale git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@955 d19143bc-622f-0410-bfdd-b5b2a6649095 --- diff --git a/ChangeLog b/ChangeLog index 4e3830f..a28bfe0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2007-02-07 Dan Dennedy + Added ffmpeg libswscale support to avformat module (requires configure + option --avformat-swscale) + 2006-12-07 Dan Dennedy > 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." diff --git a/src/modules/avformat/consumer_avformat.c b/src/modules/avformat/consumer_avformat.c index 21242c6..3348755 100644 --- a/src/modules/avformat/consumer_avformat.c +++ b/src/modules/avformat/consumer_avformat.c @@ -35,6 +35,9 @@ // avformat header files #include +#ifdef SWSCALE +#include +#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 ) diff --git a/src/modules/avformat/filter_avcolour_space.c b/src/modules/avformat/filter_avcolour_space.c index 9ea2b8f..976bb35 100644 --- a/src/modules/avformat/filter_avcolour_space.c +++ b/src/modules/avformat/filter_avcolour_space.c @@ -24,6 +24,9 @@ // ffmpeg Header files #include +#ifdef SWSCALE +#include +#endif #include #include @@ -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 :-). diff --git a/src/modules/avformat/producer_avformat.c b/src/modules/avformat/producer_avformat.c index 78c0d48..2747860 100644 --- a/src/modules/avformat/producer_avformat.c +++ b/src/modules/avformat/producer_avformat.c @@ -26,6 +26,9 @@ // ffmpeg Header files #include +#ifdef SWSCALE +#include +#endif // System header files #include @@ -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.