@@ -14,26 +14,26 @@ from av.dictionary import Dictionary
1414
1515
1616class HWDeviceType (IntEnum ):
17- NONE = lib.AV_HWDEVICE_TYPE_NONE
18- VDPAU = lib.AV_HWDEVICE_TYPE_VDPAU
19- CUDA = lib.AV_HWDEVICE_TYPE_CUDA
20- VAAPI = lib.AV_HWDEVICE_TYPE_VAAPI
21- DXVA2 = lib.AV_HWDEVICE_TYPE_DXVA2
22- QSV = lib.AV_HWDEVICE_TYPE_QSV
23- VIDEOTOOLBOX = lib.AV_HWDEVICE_TYPE_VIDEOTOOLBOX
24- D3D11VA = lib.AV_HWDEVICE_TYPE_D3D11VA
25- DRM = lib.AV_HWDEVICE_TYPE_DRM
26- OPENCL = lib.AV_HWDEVICE_TYPE_OPENCL
27- MEDIACODEC = lib.AV_HWDEVICE_TYPE_MEDIACODEC
28- VULKAN = lib.AV_HWDEVICE_TYPE_VULKAN
29- D3D12VA = lib.AV_HWDEVICE_TYPE_D3D12VA
17+ none = lib.AV_HWDEVICE_TYPE_NONE
18+ vdpau = lib.AV_HWDEVICE_TYPE_VDPAU
19+ cuda = lib.AV_HWDEVICE_TYPE_CUDA
20+ vaapi = lib.AV_HWDEVICE_TYPE_VAAPI
21+ dxva2 = lib.AV_HWDEVICE_TYPE_DXVA2
22+ qsv = lib.AV_HWDEVICE_TYPE_QSV
23+ videotoolbox = lib.AV_HWDEVICE_TYPE_VIDEOTOOLBOX
24+ d3d11va = lib.AV_HWDEVICE_TYPE_D3D11VA
25+ drm = lib.AV_HWDEVICE_TYPE_DRM
26+ opencl = lib.AV_HWDEVICE_TYPE_OPENCL
27+ mediacodec = lib.AV_HWDEVICE_TYPE_MEDIACODEC
28+ vulkan = lib.AV_HWDEVICE_TYPE_VULKAN
29+ d3d12va = lib.AV_HWDEVICE_TYPE_D3D12VA
3030
3131class HWConfigMethod (IntEnum ):
32- NONE = 0
33- HW_DEVICE_CTX = lib.AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX # This is the only one we support.
34- HW_FRAME_CTX = lib.AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX
35- INTERNAL = lib.AV_CODEC_HW_CONFIG_METHOD_INTERNAL
36- AD_HOC = lib.AV_CODEC_HW_CONFIG_METHOD_AD_HOC
32+ none = 0
33+ hw_device_ctx = lib.AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX # This is the only one we support.
34+ hw_frame_ctx = lib.AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX
35+ internal = lib.AV_CODEC_HW_CONFIG_METHOD_INTERNAL
36+ ad_hoc = lib.AV_CODEC_HW_CONFIG_METHOD_AD_HOC
3737
3838
3939cdef object _cinit_sentinel = object ()
@@ -82,30 +82,22 @@ cdef class HWConfig:
8282 def is_supported (self ):
8383 return bool (self .ptr.methods & lib.AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX)
8484
85- hwdevices_available = []
8685
87- cdef lib.AVHWDeviceType x = lib.AV_HWDEVICE_TYPE_NONE
88- while True :
89- x = lib.av_hwdevice_iterate_types(x)
90- if x == lib.AV_HWDEVICE_TYPE_NONE:
91- break
92- hwdevices_available.append(lib.av_hwdevice_get_type_name(HWDeviceType(x)))
86+ cpdef hwdevices_available():
87+ result = []
9388
94- def dump_hwdevices ():
95- print (" Hardware device types:" )
96- for x in hwdevices_available:
97- print (" " , x)
89+ cdef lib.AVHWDeviceType x = lib.AV_HWDEVICE_TYPE_NONE
90+ while True :
91+ x = lib.av_hwdevice_iterate_types(x)
92+ if x == lib.AV_HWDEVICE_TYPE_NONE:
93+ break
94+ result.append(lib.av_hwdevice_get_type_name(HWDeviceType(x)))
95+
96+ return result
9897
9998
10099cdef class HWAccel:
101- def __init__ (
102- self ,
103- device_type: str | HWDeviceType ,
104- device: str | None = None ,
105- allow_software_fallback: bool = True ,
106- options = None ,
107- **kwargs ,
108- ):
100+ def __init__ (self , device_type , device = None , allow_software_fallback = True , options = None ):
109101 if isinstance (device_type, HWDeviceType):
110102 self ._device_type = device_type
111103 elif isinstance (device_type, str ):
@@ -115,25 +107,22 @@ cdef class HWAccel:
115107
116108 self ._device = device
117109 self .allow_software_fallback = allow_software_fallback
110+ self .options = {} if not options else dict (options)
118111
119- if options and kwargs:
120- raise ValueError (" accepts only one of options arg or kwargs" )
121- self .options = dict (options or kwargs)
122-
123- def create (self , Codec codec ):
112+ def create (self , Codec codec not None ):
124113 return HWAccelContext(
125- device_type = HWDeviceType(self ._device_type),
126- device = self ._device,
127- options = self .options,
128- codec = codec ,
129- allow_software_fallback = self .allow_software_fallback ,
114+ HWDeviceType(self ._device_type),
115+ self ._device,
116+ self .options,
117+ self .allow_software_fallback ,
118+ codec ,
130119 )
131120
132121cdef class HWAccelContext(HWAccel):
133- def __init__ (self , device_type , device , options , codec , allow_software_fallback , ** kwargs ):
134- super ().__init__(device_type, device, options, ** kwargs )
122+ def __init__ (self , device_type , device , allow_software_fallback , options , codec ):
123+ super ().__init__(device_type, device, options)
135124 if not codec:
136- raise ValueError (" codec is required" )
125+ raise ValueError (" ` codec` is required" )
137126 self .codec = codec
138127 cdef HWConfig config
139128
@@ -144,7 +133,7 @@ cdef class HWAccelContext(HWAccel):
144133 continue
145134 break
146135 else :
147- raise NotImplementedError (f" no supported hardware config for {codec}" )
136+ raise NotImplementedError (f" No supported hardware config for {codec}" )
148137
149138 self .config = config
150139 cdef char * c_device = NULL
@@ -162,6 +151,3 @@ cdef class HWAccelContext(HWAccel):
162151 def __dealloc__ (self ):
163152 if self .ptr:
164153 lib.av_buffer_unref(& self .ptr)
165-
166- def create (self , *args , **kwargs ):
167- raise ValueError (" cannot call HWAccelContext.create" )
0 commit comments