简体   繁体   English

在使用真正的网络摄像头的同时在 linux 上使用带有谷歌铬或铬的 v4l2loopback 虚拟摄像头

[英]Using v4l2loopback virtual cam with google-chrome or chromium on linux while having real webcam in use

(I hope posting an answer to own question is not against TOS here, I made it because I discovered the solution while writing this post, and extensive googling didn't help, so I hope I can help some people looking for solution.) (我希望在这里发布对自己问题的回答不违反 TOS,我之所以这样做是因为我在写这篇文章时发现了解决方案,大量的谷歌搜索没有帮助,所以我希望我可以帮助一些寻找解决方案的人。)

Problem: Google chrome / chromium doesn't open v4l2loopback virtual camera device (won't access it) and report "No camera available", even if it is listed and selected in settings page sometimes.问题: Google chrome / Chromium 不会打开 v4l2loopback 虚拟相机设备(不会访问它)并报告“无相机可用”,即使它有时在设置页面中列出和选择。

Observed cause of problem : (noticed when using OBS Cam Studio) Google chrome / chromium WILL NOT access (open) virtual camera device if it finds real camera device being in use (busy).观察到的问题原因:(在使用 OBS Cam Studio 时注意到)如果发现真实的相机设备正在使用(忙碌),Google chrome / Chromium 将不会访问(打开)虚拟相机设备。

Solution (short version) :解决方案(简短版本)

  • find out which device your physical webcam is (it may be multiple devices) if your camera is pluggable you can disconnect it, then observe the result of ls /dev/video* , connect it, and try ls /dev/video* again to see which devices appeared (in my case it's /dev/video0 and /dev/video1 ) - in most cases it will be /dev/video0找出你的物理摄像头是哪个设备(它可能是多个设备)如果你的摄像头是可插拔的,你可以断开它,然后观察ls /dev/video* ,连接它,并再次尝试ls /dev/video*查看出现了哪些设备(在我的情况下是/dev/video0/dev/video1 ) - 在大多数情况下它将是/dev/video0
  • start your capturing program (the one that uses physical webcam and outputs to virtual camera) and make it output to virtual camera (virtual camera has to be fed with input to be opened by chrome)启动您的捕获程序(使用物理网络摄像头并输出到虚拟摄像头的程序)并使其输出到虚拟摄像头(虚拟摄像头必须输入要由 chrome 打开的输入)
  • disable access to physical webcam, which (in my case) can be done with:禁用对物理网络摄像头的访问,这(在我的情况下)可以通过以下方式完成:
sudo chmod 000 /dev/video0
sudo chmod 000 /dev/video1

(use the device names that you discovered your physical webcam is) (使用您发现物理网络摄像头的设备名称)

  • start the video capture in google chrome/chromium (by opening the webpage or pressing some sort of "Start webcam", it depends on the webpage)在谷歌浏览器/铬中启动视频捕获(通过打开网页或按某种“启动网络摄像头”,这取决于网页)
  • you should see virtual camera feed in chrome now您现在应该可以在 chrome 中看到虚拟相机输入
  • enable access to physical webcam back, done (in my case) with:启用对物理网络摄像头的访问,完成(在我的情况下):
sudo chmod 660 /dev/video0
sudo chmod 660 /dev/video1
  • and done!并做了! have fun camming on the web!在网络上玩得开心!

Solution (long version) : Description, step by step, how to make OBS Cam Studio virtual output be visible in google chrome/chromium.解决方案(长版) :分步说明如何使 OBS Cam Studio 虚拟输出在 google chrome/chromium 中可见。

  • if you didn't do it yet, unload v4l2loopback module (do it if you weren't aware of "exclusive_caps" parameter):如果您还没有这样做,请卸载 v4l2loopback 模块(如果您不知道“exclusive_caps”参数,请执行此操作):
sudo modprobe -r v4l2loopback

(you need to stop any virual camera feed and stop application that uses virtual cam, otherwise you will get modprobe: FATAL: Module v4l2loopback is in use. error) (您需要停止任何虚拟摄像头馈送并停止使用虚拟摄像头的应用程序,否则您将收到modprobe: FATAL: Module v4l2loopback is in use.错误)

  • load v4l2loopback module (only "exclusive_caps" parameter matters):加载 v4l2loopback 模块(只有“exclusive_caps”参数很重要):
sudo modprobe v4l2loopback devices=1 video_nr=21 exclusive_caps=1 card_label="Virtual Webcam"

(this command will create one loopback device with name /dev/video21 and name (caption) "Virtual Webcam") simpler version of the command, that really matters: (此命令将创建一个名为/dev/video21和名称(标题)“Virtual Webcam”的环回设备)该命令的更简单版本,这真的很重要:

sudo modprobe v4l2loopback exclusive_caps=1
  • start video capture program that uses your physical webcam and outputs to virtual webcam device (in my case it's OBS Cam Studio) - physical webcam should be busy (in use) now and virtual webcam should be fed input (important)启动使用物理网络摄像头的视频捕获程序并输出到虚拟网络摄像头设备(在我的情况下是 OBS Cam Studio) - 现在物理网络摄像头应该很忙(正在使用)并且虚拟网络摄像头应该输入(重要)
  • disable physical webcam devices access by (in my case):通过(在我的情况下)禁用物理网络摄像头设备访问:
sudo chmod 000 /dev/video0
sudo chmod 000 /dev/video1

(device names may be different in your case and there may be just one of them) (if you have no sudo access and your camera is pluggable you can just unplug it) (在您的情况下设备名称可能不同,并且可能只有其中一个)(如果您没有 sudo 访问权限并且您的相机是可插拔的,您可以拔掉它)

  • start using webcam with google chrome or chromium (enter the web page and open the webcam on it, for example by button "Use my webcam" on the web page - it is different from page to page)开始使用带有谷歌浏览器或铬的网络摄像头(进入网页并在其上打开网络摄像头,例如通过网页上的“使用我的网络摄像头”按钮 - 它因页面而异)
  • you should see the virtual webcam feed now (if not, click the camera icon on the right of address bar, click "Manage" and select your virtual webcam by name in settings, make web page use webcam again)您现在应该看到虚拟网络摄像头提要(如果没有,请单击地址栏右侧的摄像头图标,单击“管理”并在设置中按名称选择您的虚拟网络摄像头,再次使网页使用网络摄像头)
  • enable physical webcam devices access back by (in my case):通过(在我的情况下)启用物理网络摄像头设备访问:
sudo chmod 660 /dev/video0
sudo chmod 660 /dev/video1

(in case you unplugged the webcam plug it back and (possibly) reopen it in your program) (如果您拔掉网络摄像头,将其插回并(可能)在您的程序中重新打开它)

  • enjoy virtual webcam in chrome!享受 chrome 中的虚拟网络摄像头!

I hope it helps as I struggled for a long time with no effect to make google chrome open virtual webcam in OBS Cam Studio.我希望它有所帮助,因为我挣扎了很长时间,但在 OBS Cam Studio 中使 google chrome 打开虚拟网络摄像头没有任何效果。

Edited : Found working solution that is based on similar principle, it's here: https://www.scs.stanford.edu/~dm/blog/hide-webcam.html It hides physical webcam from the list of visible webcams, so you need to enter the path to it manually or in the config settings of the program.编辑:找到基于类似原理的工作解决方案,它在这里: https : //www.scs.stanford.edu/~dm/blog/hide-webcam.html它从可见网络摄像头列表中隐藏物理网络摄像头,所以你需要手动或在程序的配置设置中输入它的路径。

回答我自己的帖子以将其标记为“已回答”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM