diff -ru pyffmpeg-0.2.0-orig/pyffmpeg/pyffmpeg.pyx pyffmpeg-0.2.0/pyffmpeg/pyffmpeg.pyx --- pyffmpeg-0.2.0-orig/pyffmpeg/pyffmpeg.pyx 2007-01-17 22:21:29.000000000 +0100 +++ pyffmpeg-0.2.0/pyffmpeg/pyffmpeg.pyx 2008-07-16 11:00:12.000000000 +0200 @@ -89,7 +89,6 @@ AVDISCARD_NONKEY = 32 # discard all frames except keyframes AVDISCARD_ALL = 48 # discard all - struct AVCodecContext: int codec_type int codec_id @@ -143,6 +142,7 @@ struct AVPicture: pass + AVCodec *avcodec_find_decoder(int id) int avcodec_open(AVCodecContext *avctx, AVCodec *codec) int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture, @@ -154,13 +154,31 @@ int avpicture_get_size(int pix_fmt, int width, int height) int avpicture_layout(AVPicture* src, int pix_fmt, int width, int height, unsigned char *dest, int dest_size) - int img_convert(AVPicture *dst, int dst_pix_fmt, - AVPicture *src, int pix_fmt, - int width, int height) void avcodec_flush_buffers(AVCodecContext *avctx) +cdef extern from "swscale.h": + cdef enum SWScaleFlags: + SWS_FAST_BILINEAR = 1 + SWS_BILINEAR = 2 + SWS_BICUBIC = 4 + + struct SWScaleVector: + double *coeff + int length + + struct SWScaleFilter: + SWScaleVector *lumH + SWScaleVector *lumV + SWScaleVector *chrH + SWScaleVector *chrV + + struct SWScaleContext: + pass + SWScaleContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags, SWScaleFilter *srcFilter, SWScaleFilter *dstFilter, double *param) + int sws_scale(SWScaleContext *swsContext, char *src[], int srcStride[], int srcSliceY, int srcSliceH, char *dst[], int dstStride[]) + void sws_freeContext(SWScaleContext *swsContext) cdef extern from "avformat.h": struct AVFrac: @@ -241,7 +259,6 @@ # av_seek_frame() support int64_t data_offset # offset of the first packet int index_built - struct AVInputFormat: pass @@ -269,7 +286,6 @@ int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags) - cdef extern from "avio.h": int url_ferror(ByteIOContext *s) int url_feof(ByteIOContext *s) @@ -350,11 +366,12 @@ raise IOError("Unable to open codec") self.filename = filename - cdef AVFrame *ConvertToRGBA(self,AVPicture *frame,AVCodecContext *pCodecCtx): + cdef AVFrame *ConvertToRGBA(self,AVFrame *frame,AVCodecContext *pCodecCtx): cdef AVFrame *pFrameRGBA cdef int numBytes cdef char *rgb_buffer cdef int width,height + cdef SWScaleContext *img_convert_ctx pFrameRGBA = avcodec_alloc_frame() if pFrameRGBA == NULL: @@ -363,22 +380,24 @@ width = pCodecCtx.width height = pCodecCtx.height # Determine required buffer size and allocate buffer - numBytes=avpicture_get_size(PIX_FMT_RGBA32, width,height) + numBytes = avpicture_get_size(PIX_FMT_RGBA32, width,height) # Hrm, how do I figure out when to release the old one.... rgb_buffer = PyMem_Malloc(numBytes) avpicture_fill(pFrameRGBA, rgb_buffer, PIX_FMT_RGBA32, width, height) - img_convert(pFrameRGBA, PIX_FMT_RGBA32, - frame, pCodecCtx.pix_fmt, width, - height) + img_convert_ctx = sws_getContext(width, height, pCodecCtx.pix_fmt, width, height, PIX_FMT_RGBA32, SWS_BICUBIC, NULL, NULL, NULL) + sws_scale(img_convert_ctx, frame.data, frame.linesize, 0, height, pFrameRGBA.data, pFrameRGBA.linesize) + sws_freeContext(img_convert_ctx) + return pFrameRGBA - cdef AVFrame *ConvertToRGB24(self,AVPicture *frame,AVCodecContext *pCodecCtx): + cdef AVFrame *ConvertToRGB24(self,AVFrame *frame,AVCodecContext *pCodecCtx): cdef AVFrame *pFrameRGB24 cdef int numBytes cdef char *rgb_buffer cdef int width,height + cdef SWScaleContext *img_convert_ctx pFrameRGB24 = avcodec_alloc_frame() if pFrameRGB24 == NULL: @@ -387,15 +406,16 @@ width = pCodecCtx.width height = pCodecCtx.height # Determine required buffer size and allocate buffer - numBytes=avpicture_get_size(PIX_FMT_RGB24, width,height) + numBytes = avpicture_get_size(PIX_FMT_RGB24, width,height) # Hrm, how do I figure out how to release the old one.... rgb_buffer = PyMem_Malloc(numBytes) avpicture_fill(pFrameRGB24, rgb_buffer, PIX_FMT_RGB24, width, height) - img_convert(pFrameRGB24, PIX_FMT_RGB24, - frame, pCodecCtx.pix_fmt, width, - height) + img_convert_ctx = sws_getContext(width, height, pCodecCtx.pix_fmt, width, height, PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL) + sws_scale(img_convert_ctx, frame.data, frame.linesize, 0, height, pFrameRGB24.data, pFrameRGB24.linesize) + sws_freeContext(img_convert_ctx) + return pFrameRGB24 def SaveFrame(self): @@ -408,7 +428,7 @@ height = self.CodecCtx.height # I haven't figured out how to write RGBA data to an ppm file so I use a 24 bit version - pFrameRGB = self.ConvertToRGB24(self.frame,self.CodecCtx) + pFrameRGB = self.ConvertToRGB24(self.frame,self.CodecCtx) filename = "frame%04d.ppm" % self.frameno f = open(filename,"wb") @@ -424,8 +444,8 @@ cdef object buf_obj cdef int numBytes - pFrameRGB = self.ConvertToRGBA(self.frame,self.CodecCtx) - numBytes=avpicture_get_size(PIX_FMT_RGBA32, self.CodecCtx.width, self.CodecCtx.height) + pFrameRGB = self.ConvertToRGBA(self.frame,self.CodecCtx) + numBytes = avpicture_get_size(PIX_FMT_RGBA32, self.CodecCtx.width, self.CodecCtx.height) buf_obj = PyBuffer_FromMemory(pFrameRGB.data[0],numBytes) img_image = Image.frombuffer("RGBA",(self.CodecCtx.width,self.CodecCtx.height),buf_obj,"raw","BGRA",pFrameRGB.linesize[0],1) diff -ru pyffmpeg-0.2.0-orig/setup.py pyffmpeg-0.2.0/setup.py --- pyffmpeg-0.2.0-orig/setup.py 2007-01-17 22:15:32.000000000 +0100 +++ pyffmpeg-0.2.0/setup.py 2008-07-16 09:40:26.000000000 +0200 @@ -1,32 +1,34 @@ -from distutils.core import setup -from distutils.extension import Extension -from Pyrex.Distutils import build_ext - -import sys -if sys.platform == 'win32': - setup( - name = "pyffmpeg", - ext_modules=[ - Extension("pyffmpeg", ["pyffmpeg.pyx"], - define_macros=[('EMULATE_INTTYPES', '1')], - include_dirs=["/usr/include/ffmpeg"], - library_dirs=[r"\usr\lib"], - libraries = ["avutil-49","avformat-50","avcodec-51"]) - ], - cmdclass = {'build_ext': build_ext} - ) -else: - setup( - name = "pyffmpeg", - ext_modules=[ - Extension("pyffmpeg", ["pyffmpeg.pyx"], - include_dirs=["/usr/include/ffmpeg"], - libraries = ["avformat","avcodec"]) - ], - cmdclass = {'build_ext': build_ext}, - version = "0.2.0", - author = "James Evans", - author_email = "jaevans@users.sf.net", - url = "http://www.clark-evans.com/~milamber/pyffmpeg", - ) - +from distutils.core import setup +from distutils.extension import Extension +from Pyrex.Distutils import build_ext + +import sys +if sys.platform == 'win32': + setup( + name = "pyffmpeg", + ext_modules=[ + Extension("pyffmpeg", ["pyffmpeg.pyx"], + define_macros=[('EMULATE_INTTYPES', '1')], + include_dirs=["/usr/include/ffmpeg"], + library_dirs=[r"\usr\lib"], + libraries = ["avutil-49","avformat-50","avcodec-51"]) + ], + cmdclass = {'build_ext': build_ext} + ) +else: + setup( + name = "pyffmpeg", + packages = ['pyffmpeg'], + ext_package='pyffmpeg', + ext_modules=[ + Extension("pyffmpeg", ["pyffmpeg/pyffmpeg.pyx"], + include_dirs=["/usr/include/libavutil", "/usr/include/libavcodec", "/usr/include/libavformat", "/usr/include/libswscale"], + libraries = ["avformat","avcodec","swscale"]) + ], + cmdclass = {'build_ext': build_ext}, + version = "0.2.0", + author = "James Evans", + author_email = "jaevans@users.sf.net", + url = "http://www.clark-evans.com/~milamber/pyffmpeg", + ) +