31
31
from utils .misc_utils import os_type
32
32
33
33
if os_type == 'Linux' :
34
- import v4l2
34
+ import v4l2py as v4l
35
+ import v4l2py .device as v4ld
35
36
elif os_type == 'Windows' :
36
37
import pygrabber .dshow_graph as pgdsg
37
38
import pygrabber .dshow_ids as pgdsi
@@ -49,7 +50,7 @@ class ControlType(Enum):
49
50
class Control :
50
51
"""Control defined by the hardware."""
51
52
def __init__ (self : "FTCamera.ControlInfo" ,
52
- control : int ) -> None :
53
+ control : v4ld . BaseControl ) -> None :
53
54
self ._control = control
54
55
self .name = control .name
55
56
self .type = None
@@ -60,17 +61,17 @@ def __init__(self: "FTCamera.ControlInfo",
60
61
self .clipping : bool = False
61
62
self .choices : dict [int : str ] = {}
62
63
match control .type :
63
- case v4l2 . uapi . V4L2_CTRL_TYPE_INTEGER :
64
+ case v4ld . ControlType . INTEGER :
64
65
self .type = FTCamera .ControlType .INTEGER
65
66
self .minimum = control .minimum
66
67
self .maximum = control .maximum
67
68
self .step = control .step
68
69
self .default = control .default
69
70
self .clipping = control .clipping
70
- case v4l2 . uapi . V4L2_CTRL_TYPE_BOOLEAN :
71
+ case v4ld . ControlType . BOOLEAN :
71
72
self .type = FTCamera .ControlType .BOOLEAN
72
73
self .default = control .default
73
- case v4l2 . uapi . V4L2_CTRL_TYPE_MENU :
74
+ case v4ld . ControlType . MENU :
74
75
self .type = FTCamera .ControlType .SELECT
75
76
self .choices = dict (control .data )
76
77
self .default = control .default
@@ -165,7 +166,7 @@ def __init__(self: 'FTCamera', index: int) -> None:
165
166
"""
166
167
self ._index : int = index
167
168
if os_type == 'Linux' :
168
- self ._device : v4l2 . VideoDevice = None
169
+ self ._device : v4l . Device = None
169
170
elif os_type == 'Windows' :
170
171
self ._device : pgdsg .VideoInput = None
171
172
self ._filter_graph : pgdsg .FilterGraph = None
@@ -210,7 +211,7 @@ def open(self: 'FTCamera') -> None:
210
211
return
211
212
FTCamera ._logger .info ("FTCamera.open: index {}" .format (self ._index ))
212
213
if os_type == 'Linux' :
213
- self ._device = v4l2 . VideoDevice (self ._index )
214
+ self ._device = v4l . Device . from_id (self ._index )
214
215
self ._device .open ()
215
216
elif os_type == 'Windows' :
216
217
self ._filter_graph = pgdsg .FilterGraph ()
@@ -248,7 +249,7 @@ def _find_format(self: 'FTCamera') -> None:
248
249
for x in self ._device .info .formats :
249
250
FTCamera ._logger .info ("- {}" .format (x ))
250
251
self ._format = next (x for x in self ._device .info .formats
251
- if x .pixel_format == v4l2 .PixelFormat .YUYV )
252
+ if x .pixel_format == v4l .PixelFormat .YUYV )
252
253
elif os_type == 'Windows' :
253
254
for x in self ._filter_video .get_formats ():
254
255
FTCamera ._logger .info (x )
@@ -291,7 +292,11 @@ def _find_frame_size(self: 'FTCamera') -> None:
291
292
def _set_frame_format (self : 'FTCamera' ) -> None :
292
293
"""Activates the found format and size."""
293
294
if os_type == 'Linux' :
294
- self ._device .set_format ()
295
+ self ._device .set_format (
296
+ buffer_type = v4ld .BufferType .VIDEO_CAPTURE ,
297
+ width = self ._frame_size .width ,
298
+ height = self ._frame_size .height ,
299
+ pixel_format = self ._format .pixel_format )
295
300
elif os_type == 'Windows' :
296
301
self ._filter_video .set_format (self ._frame_size .index )
297
302
0 commit comments