Source

FFVideo / some.patch

diff -r 3a317984a512 ffvideo/ffmpeg.pxd
--- a/ffvideo/ffmpeg.pxd        Sat Sep 10 03:33:21 2011 +0400
+++ b/ffvideo/ffmpeg.pxd        Thu Apr 12 14:43:47 2012 +0200
@@ -19,8 +19,6 @@
     int64_t av_rescale(int64_t a, int64_t b, int64_t c)
     int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
 
-
-
 cdef extern from "libavutil/avutil.h":
     cdef enum PixelFormat:
         PIX_FMT_NONE= -1,
@@ -48,7 +46,14 @@
         PIX_FMT_UYVY411,   #< Packed pixel, Cb Y0 Y1 Cr Y2 Y3
         PIX_FMT_NB,
 
-cdef extern from "libavutil/avutil.h":
+    struct AVDictionaryEntry:
+        char *key
+        char *value
+
+    struct AVDictionary:
+        int count
+        AVDictionaryEntry *elems
+
     void av_free(void *) nogil
     void av_freep(void *) nogil
 
@@ -86,6 +91,14 @@
         AVDISCARD_NONKEY =  32 # discard all frames except keyframes
         AVDISCARD_ALL    =  48 # discard all
 
+    enum AVMediaType:
+        AVMEDIA_TYPE_UNKNOWN = -1
+        AVMEDIA_TYPE_VIDEO = 0
+        AVMEDIA_TYPE_AUDIO = 1
+        AVMEDIA_TYPE_DATA = 2
+        AVMEDIA_TYPE_SUBTITLE = 3
+        AVMEDIA_TYPE_ATTACHMENT = 4
+        AVMEDIA_TYPE_NB = 5
 
     struct AVCodecContext:
         int max_b_frames
@@ -100,13 +113,6 @@
         int skip_idct
         int skip_frame
         AVRational time_base
-        
-    enum CodecType:
-        CODEC_TYPE_UNKNOWN = -1
-        CODEC_TYPE_VIDEO = 0
-        CODEC_TYPE_AUDIO = 1
-        CODEC_TYPE_DATA = 2
-        CODEC_TYPE_SUBTITLE = 3
 
     struct AVCodec:
         char *name
@@ -144,9 +150,9 @@
         int linesize[4]
 
     AVCodec *avcodec_find_decoder(int id)
-    int avcodec_open(AVCodecContext *avctx, AVCodec *codec)
-    int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
-                         int *got_picture_ptr, char *buf, int buf_size) nogil
+    int avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options)
+    int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
+                         int *got_picture_ptr, AVPacket *avpkt) nogil
     int avpicture_fill(AVPicture *picture, void *ptr, int pix_fmt, int width, int height) nogil
     AVFrame *avcodec_alloc_frame()
     int avpicture_get_size(int pix_fmt, int width, int height)
@@ -159,8 +165,6 @@
     void avcodec_flush_buffers(AVCodecContext *avctx)
     int avcodec_close (AVCodecContext *avctx)
 
-
-
 cdef extern from "libavformat/avformat.h":
     struct AVFrac:
         int64_t val, num, den
@@ -182,7 +186,7 @@
         # approximately 3600 or 1800 timer ticks then r_frame_rate will be 50/1
         AVRational r_frame_rate
         void *priv_data
-        # internal data used in av_find_stream_info()
+        # internal data used in avformat_find_stream_info()
         int64_t codec_info_duration
         int codec_info_nb_frames
         # encoding: PTS generation when outputing stream
@@ -245,17 +249,12 @@
         int index_built
         int flags
 
+    int avformat_open_input(AVFormatContext **ic_ptr, char *filename,
+                       AVInputFormat *fmt,
+                       AVDictionary **options)
+    int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
 
-    struct AVFormatParameters:
-        pass
-
-    int av_open_input_file(AVFormatContext **ic_ptr, char *filename,
-                       AVInputFormat *fmt,
-                       int buf_size,
-                       AVFormatParameters *ap)
-    int av_find_stream_info(AVFormatContext *ic)
-
-    void dump_format(AVFormatContext *ic,
+    void av_dump_format(AVFormatContext *ic,
                  int index,
                  char *url,
                  int is_output)
@@ -268,14 +267,12 @@
     void av_parser_close(AVCodecParserContext *s)
 
     int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
-    void av_close_input_file(AVFormatContext *s)
-
+    void avformat_close_input(AVFormatContext **s)
 
 cdef extern from "libavformat/avio.h":
     int url_ferror(ByteIOContext *s)
     int url_feof(ByteIOContext *s)
 
-
 cdef extern from "libswscale/swscale.h":
     int SWS_FAST_BILINEAR
     int SWS_BILINEAR
@@ -284,11 +281,13 @@
     struct SwsVector:
         double *coeff
         int length
+
     struct SwsFilter:
         SwsVector *lumH
         SwsVector *lumV
         SwsVector *chrH
         SwsVector *chrV
+
     struct SwsContext:
         pass
 
@@ -299,5 +298,3 @@
 
     int sws_scale(SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
                     int srcSliceH, uint8_t* dst[], int dstStride[]) nogil
-
-
diff -r 3a317984a512 ffvideo/ffvideo.pyx
--- a/ffvideo/ffvideo.pyx       Sat Sep 10 03:33:21 2011 +0400
+++ b/ffvideo/ffvideo.pyx       Thu Apr 12 14:43:47 2012 +0200
@@ -135,16 +135,16 @@
         self.frame_mode = frame_mode
         self.scale_mode = scale_mode
 
-        ret = av_open_input_file(&self.format_ctx, filename, NULL, 0, NULL)
+        ret = avformat_open_input(&self.format_ctx, filename, NULL, NULL)
         if ret != 0:
             raise DecoderError("Unable to open file %s" % filename)
 
-        ret = av_find_stream_info(self.format_ctx)
+        ret = avformat_find_stream_info(self.format_ctx, NULL)
         if ret < 0:
             raise DecoderError("Unable to find stream info: %d" % ret)
 
         for i in xrange(self.format_ctx.nb_streams):
-            if self.format_ctx.streams[i].codec.codec_type == CODEC_TYPE_VIDEO:
+            if self.format_ctx.streams[i].codec.codec_type == AVMEDIA_TYPE_VIDEO:
                 self.streamno = i
                 break
         else:
@@ -171,11 +171,11 @@
         self.height = self.codec_ctx.height
 
         # Open codec
-        ret = avcodec_open(self.codec_ctx, self.codec)
+        ret = avcodec_open2(self.codec_ctx, self.codec, NULL)
         if ret < 0:
             raise DecoderError("Unable to open codec")
 
-        # for some videos, avcodec_open will set these to 0,
+        # for some videos, avcodec_open2 will set these to 0,
         # so we'll only be using it if it is not 0, otherwise,
         # we rely on the resolution provided by the header;
         if self.codec_ctx.width != 0 and self.codec_ctx.height !=0:
@@ -203,13 +203,12 @@
             avcodec_close(self.codec_ctx)
             self.codec_ctx = NULL
         if self.format_ctx:
-            av_close_input_file(self.format_ctx)
-            self.format_ctx = NULL
+            avformat_close_input(&self.format_ctx)
 
     def dump(self):
         print "max_b_frames=%s" % self.codec_ctx.max_b_frames
         av_log_set_level(AV_LOG_VERBOSE);
-        dump_format(self.format_ctx, 0, self.filename, 0);
+        av_dump_format(self.format_ctx, 0, self.filename, 0);
         av_log_set_level(AV_LOG_ERROR);
 
     def __decode_next_frame(self):
@@ -224,9 +223,8 @@
 
             if self.packet.stream_index == self.streamno:
                 with nogil:
-                    ret = avcodec_decode_video(self.codec_ctx, self.frame,
-                                               &frame_finished,
-                                               self.packet.data, self.packet.size)
+                    ret = avcodec_decode_video2(self.codec_ctx, self.frame,
+                                               &frame_finished, &self.packet)
                 if ret < 0:
                     av_free_packet(&self.packet)
                     raise IOError("Unable to decode video picture: %d" % ret)