-
Notifications
You must be signed in to change notification settings - Fork 434
Expand file tree
/
Copy pathfilter.py
More file actions
80 lines (63 loc) · 2 KB
/
filter.py
File metadata and controls
80 lines (63 loc) · 2 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
79
80
import cython
from cython.cimports import libav as lib
from cython.cimports.av.descriptor import wrap_avclass
from cython.cimports.av.filter.link import alloc_filter_pads
_cinit_sentinel = cython.declare(object, object())
@cython.cfunc
def wrap_filter(ptr: cython.pointer[cython.const[lib.AVFilter]]) -> Filter:
filter_: Filter = Filter(_cinit_sentinel)
filter_.ptr = ptr
return filter_
@cython.cclass
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
@cython.cfunc
def get_filter_names() -> set:
names: set = set()
ptr: cython.pointer[cython.const[lib.AVFilter]]
opaque: cython.p_void = cython.NULL
while True:
ptr = lib.av_filter_iterate(cython.address(opaque))
if ptr:
names.add(ptr.name)
else:
break
return names
filters_available = get_filter_names()
filter_descriptor = wrap_avclass(lib.avfilter_get_class())