-
Notifications
You must be signed in to change notification settings - Fork 434
Expand file tree
/
Copy pathfilter.pyx
More file actions
78 lines (59 loc) · 1.81 KB
/
filter.pyx
File metadata and controls
78 lines (59 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
cimport libav as lib
from av.descriptor cimport wrap_avclass
from av.filter.link cimport alloc_filter_pads
cdef object _cinit_sentinel = object()
cdef Filter wrap_filter(const lib.AVFilter *ptr):
cdef Filter filter_ = Filter(_cinit_sentinel)
filter_.ptr = ptr
return filter_
cdef class Filter:
def __cinit__(self, name):
if name is _cinit_sentinel:
return
if not isinstance(name, str):
raise TypeError("takes a filter name as a string")
self.ptr = lib.avfilter_get_by_name(name)
if not self.ptr:
raise ValueError(f"no filter {name}")
@property
def descriptor(self):
if self._descriptor is None:
self._descriptor = wrap_avclass(self.ptr.priv_class)
return self._descriptor
@property
def options(self):
if self.descriptor is None:
return
return self.descriptor.options
@property
def name(self):
return self.ptr.name
@property
def description(self):
return self.ptr.description
@property
def flags(self):
return self.ptr.flags
@property
def inputs(self):
if self._inputs is None:
self._inputs = alloc_filter_pads(self, self.ptr.inputs, True)
return self._inputs
@property
def outputs(self):
if self._outputs is None:
self._outputs = alloc_filter_pads(self, self.ptr.outputs, False)
return self._outputs
cdef get_filter_names():
names = set()
cdef const lib.AVFilter *ptr
cdef void *opaque = NULL
while True:
ptr = lib.av_filter_iterate(&opaque)
if ptr:
names.add(ptr.name)
else:
break
return names
filters_available = get_filter_names()
filter_descriptor = wrap_avclass(lib.avfilter_get_class())