2017-02-14 60 views
0

我剛開始在Ubuntu 16.04.v4l2文檔的示例代碼原樣(打開爲'rw')?

我試圖從運行V4L2 Python文檔樣本,即使用v4l2(用於Python 3):

$ cat demo4SO.py 
#!/usr/bin/env python3 

import v4l2 
import fcntl 

vd = open('/dev/video0', 'rw') 
#vd = open('/dev/video0', 'r') 
cp = v4l2.v4l2_capability() 
fcntl.ioctl(vd, v4l2.VIDIOC_QUERYCAP, cp) 

print("driver:",cp.driver) 
print("card:",cp.card) 

但我越來越:

$ python3 demo4SO.py 
Traceback (most recent call last): 
    File "demo4SO.py", line 6, in <module> 
    vd = open('/dev/video0', 'rw') 
ValueError: must have exactly one of create/read/write/append mode 

即使與sudo.一起運行,我也會得到相同的錯誤

試圖用 'W +'(或 'R +'),我可以打開:

$ python3 demo4SO.py 
Traceback (most recent call last): 
    File "demo4SO.py", line 8, in <module> 
    vd = open('/dev/video0', "w+") 
io.UnsupportedOperation: File or stream is not seekable. 

如果我改變 'RW'(或 'W +' 或 'R +'),以 'R',代碼工作作爲預期。

$ cat demo4SO.py 
#!/usr/bin/env python3 

import v4l2 
import fcntl 

#vd = open('/dev/video0', 'rw') 
vd = open('/dev/video0', 'r') 
cp = v4l2.v4l2_capability() 
fcntl.ioctl(vd, v4l2.VIDIOC_QUERYCAP, cp) 

print("driver:",cp.driver) 
print("card:",cp.card) 


$ python3 demo4SO.py 
driver: b'uvcvideo' 
card: b'Intel(R) RealSense(TM) 410' 

我的用戶名屬於該組的視頻設備,所以看起來問題並不涉及到權限:

$ groups 
openstack root sudo video staff 
$ ls -ls /dev/video0 
0 crw-rw----+ 1 root video 81, 0 פבר 14 11:31 /dev/video0 

任何想法,爲什麼我不能運行的文檔的示例代碼是('rw')?

回答

1

更改

vd = open('/dev/video0', 'rw') 

vd = open('/dev/video0', 'rb+', buffering=0) 

能夠打開與O_RDWR權限的文件。