在Docker中使用cvlc访问主机摄像头

我正在尝试为stream式服务器设置一个Docker容器,但是当我尝试从容器内访问主机的摄像头时遇到了麻烦。

我使用以下命令运行容器: docker run -t -i --privileged --rm my/image /bin/bash 。 VLC拒绝以root身份运行,所以我在Dockerfile中创build了一个新用户。

这里是我用来testingnetworking摄像头工作的命令: cvlc v4l2:///dev/video2:chroma=h264 --sout '#std{access=file,mux=ps,dst=test.h264}' 。 一切按照预期在主机上运行。

当我尝试在容器中运行命令时,我看到以下内容:

 [0x7fc300003108] mux_ps mux: Open [0x7fc300003108] main mux debug: using sout mux module "mux_ps" [0x7fc300000b78] main stream output debug: muxer support adding stream at any time [0x7fc300000b78] main stream output debug: muxer prefers to wait for all ES before starting to mux [0x7fc300000f48] stream_out_standard stream out debug: using `file/ps://test.mp4' [0x7fc300000f48] main stream out debug: using sout stream module "stream_out_standard" [0x7fc308000ab8] main input debug: using timeshift granularity of 50 MiB, in path '/tmp' [0x7fc308000ab8] main input debug: `v4l2:///dev/video2:chroma=h264' gives access `v4l2' demux `' path `/dev/video2:chroma=h264' [0x7fc308000ab8] main input debug: creating demux: access='v4l2' demux='' location='/dev/video2:chroma=h264' file='/dev/video2:chroma=h264' [0x7fc300004088] main demux debug: looking for access_demux module matching "v4l2": 20 candidates [0x7fc300004088] v4l2 demux debug: opening device '/dev/video2' [0x7fc300004088] v4l2 demux error: cannot open device '/dev/video2': Permission denied [0x7fc300004088] v4l2 demux debug: opening device '/dev/video2' [0x7fc300004088] v4l2 demux error: cannot open device '/dev/video2': Permission denied [0x7fc300004088] main demux debug: no access_demux modules matched [0x7fc308000ab8] main input debug: creating access 'v4l2' location='/dev/video2:chroma=h264', path='/dev/video2:chroma=h264' [0x7fc300005988] main access debug: looking for access module matching "v4l2": 25 candidates [0x7fc300005988] v4l2 access debug: opening device '/dev/video2' [0x7fc300005988] v4l2 access error: cannot open device '/dev/video2': Permission denied [0x7fc300005988] main access debug: no access modules matched [0x7fc308000ab8] main input error: open of `v4l2:///dev/video2:chroma=h264' failed [0x7fc308000ab8] main input error: Your input can't be opened [0x7fc308000ab8] main input error: VLC is unable to open the MRL 'v4l2:///dev/video2:chroma=h264'. Check the log for details. [0x927218] main playlist debug: dead input 

当我尝试运行类似ffmpeg的工具时,我看到了同样的权限被拒绝的消息。 任何提示,我可能会出错哪里?

问题是我的用户不是video组的一部分。 此外,我不得不将video设备的权限更改为root.video

更多信息在这里: http : //www.tldp.org/HOWTO/html_single/Webcam-HOWTO/#PERMISSIONS