Skip to content

Instantly share code, notes, and snippets.

@mkassner
Last active December 24, 2015 21:40
Show Gist options
  • Save mkassner/f8c29b4e7c7a4806ec73 to your computer and use it in GitHub Desktop.
Save mkassner/f8c29b4e7c7a4806ec73 to your computer and use it in GitHub Desktop.
PyAv patch
From 6c83a870d1a4dabcedbf119a7ce412db82cefff7 Mon Sep 17 00:00:00 2001
From: Moritz Kassner <[email protected]>
Date: Thu, 24 Dec 2015 20:47:13 +0100
Subject: [PATCH 1/2] change constants and header name to work with ffmpeg from
v2.2.16 "Muybridge" onward.
---
av/video/format.pyx | 10 +++++-----
include/libavutil/avutil.pxd | 16 +++++++++-------
2 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/av/video/format.pyx b/av/video/format.pyx
index 18678e2..19aed22 100644
--- a/av/video/format.pyx
+++ b/av/video/format.pyx
@@ -65,26 +65,26 @@ cdef class VideoFormat(object):
property is_big_endian:
"""Pixel format is big-endian."""
- def __get__(self): return bool(self.ptr.flags & lib.PIX_FMT_BE)
+ def __get__(self): return bool(self.ptr.flags & lib.AV_PIX_FMT_FLAG_BE)
property has_palette:
"""Pixel format has a palette in data[1], values are indexes in this palette."""
- def __get__(self): return bool(self.ptr.flags & lib.PIX_FMT_PAL)
+ def __get__(self): return bool(self.ptr.flags & lib.AV_PIX_FMT_FLAG_PAL)
property is_bit_stream:
"""All values of a component are bit-wise packed end to end."""
- def __get__(self): return bool(self.ptr.flags & lib.PIX_FMT_BITSTREAM)
+ def __get__(self): return bool(self.ptr.flags & lib.AV_PIX_FMT_FLAG_BITSTREAM)
# Skipping PIX_FMT_HWACCEL
# """Pixel format is an HW accelerated format."""
property is_planar:
"""At least one pixel component is not in the first data plane."""
- def __get__(self): return bool(self.ptr.flags & lib.PIX_FMT_PLANAR)
+ def __get__(self): return bool(self.ptr.flags & lib.AV_PIX_FMT_FLAG_PLANAR)
property is_rgb:
"""The pixel format contains RGB-like data (as opposed to YUV/grayscale)."""
- def __get__(self): return bool(self.ptr.flags & lib.PIX_FMT_RGB)
+ def __get__(self): return bool(self.ptr.flags & lib.AV_PIX_FMT_FLAG_RGB)
cpdef chroma_width(self, int luma_width=0):
"""chroma_width(luma_width=0)
diff --git a/include/libavutil/avutil.pxd b/include/libavutil/avutil.pxd
index d2277e6..357a5aa 100644
--- a/include/libavutil/avutil.pxd
+++ b/include/libavutil/avutil.pxd
@@ -103,6 +103,8 @@ cdef extern from "libavutil/avutil.pyav.h" nogil:
int search_flags
)
+
+
cdef extern from "libavutil/pixdesc.h" nogil:
@@ -116,12 +118,12 @@ cdef extern from "libavutil/pixdesc.h" nogil:
unsigned int depth_minus1
cdef enum AVPixFmtFlags:
- PIX_FMT_BE
- PIX_FMT_PAL
- PIX_FMT_BITSTREAM
- PIX_FMT_HWACCEL
- PIX_FMT_PLANAR
- PIX_FMT_RGB
+ AV_PIX_FMT_FLAG_BE
+ AV_PIX_FMT_FLAG_PAL
+ AV_PIX_FMT_FLAG_BITSTREAM
+ AV_PIX_FMT_FLAG_HWACCEL
+ AV_PIX_FMT_FLAG_PLANAR
+ AV_PIX_FMT_FLAG_RGB
# See: http://ffmpeg.org/doxygen/trunk/structAVPixFmtDescriptor.html
cdef struct AVPixFmtDescriptor:
@@ -141,7 +143,7 @@ cdef extern from "libavutil/pixdesc.h" nogil:
-cdef extern from "libavutil/audioconvert.h" nogil:
+cdef extern from "libavutil/channel_layout.h" nogil:
# Layouts.
cdef uint64_t av_get_channel_layout(char* name)
--
1.9.5 (Apple Git-50.3)
From 731082a861a7688ce182c37917541cf3e320e1b9 Mon Sep 17 00:00:00 2001
From: Moritz Kassner <[email protected]>
Date: Thu, 24 Dec 2015 20:57:54 +0100
Subject: [PATCH 2/2] changed function names as well
---
av/frame.pyx | 6 +++---
include/libavcodec/avcodec.pxd | 6 +++---
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/av/frame.pyx b/av/frame.pyx
index f2f87a3..00c5bcb 100644
--- a/av/frame.pyx
+++ b/av/frame.pyx
@@ -10,11 +10,11 @@ cdef class Frame(object):
def __cinit__(self, *args, **kwargs):
with nogil:
- self.ptr = lib.avcodec_alloc_frame()
- lib.avcodec_get_frame_defaults(self.ptr)
+ self.ptr = lib.av_frame_alloc()
+ lib.av_frame_unref(self.ptr)
def __dealloc__(self):
- with nogil: lib.avcodec_free_frame(&self.ptr)
+ with nogil: lib.av_frame_free(&self.ptr)
def __repr__(self):
return 'av.%s #%d at 0x%x>' % (
diff --git a/include/libavcodec/avcodec.pxd b/include/libavcodec/avcodec.pxd
index 90f85f3..c2fe1bf 100644
--- a/include/libavcodec/avcodec.pxd
+++ b/include/libavcodec/avcodec.pxd
@@ -205,7 +205,7 @@ cdef extern from "libavcodec/avcodec.pyav.h" nogil:
uint8_t **base
void *opaque
- cdef AVFrame* avcodec_alloc_frame()
+ cdef AVFrame* av_frame_alloc()
cdef int avpicture_alloc(
AVPicture *picture,
@@ -282,7 +282,7 @@ cdef extern from "libavcodec/avcodec.pyav.h" nogil:
int align
)
- cdef void avcodec_free_frame(AVFrame **frame)
+ cdef void av_frame_free(AVFrame **frame)
cdef void av_free_packet(AVPacket*)
cdef void av_init_packet(AVPacket*)
@@ -332,7 +332,7 @@ cdef extern from "libavcodec/avcodec.pyav.h" nogil:
cdef void avsubtitle_free(AVSubtitle*)
- cdef void avcodec_get_frame_defaults(AVFrame* frame)
+ cdef void av_frame_unref(AVFrame* frame)
cdef int avcodec_get_context_defaults3(
AVCodecContext *ctx,
--
1.9.5 (Apple Git-50.3)
@mikeboers
Copy link

I've seen hints of this from a few other issues. Thanks for putting together a patch.

We either need to decide that we only support a "current" version of FFmpeg, or I get to add a bit of machinery to deal with this. I'm leaning towards the former. @markreidvfx have an opinion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment