Page 1 of 1
How to auto connect to webcam in VirtualBox?
Posted: 4. Sep 2022, 17:39
by l-w-c
It seems every time a guest machine launches, one has to manually enable the webcam again in order for the guest to be able to use it.
In addition it disconnects when I plug out the device in the real machine, and doesn't reconnect when I plug it in again.
Is there a way to have it always enabled by default (in case there's connection, of course)?
At the very least whenever the guest machine launches, to have it already be checked to begin with.
Re: How to auto connect to webcam in VirtualBox?
Posted: 4. Sep 2022, 18:57
by scottgus1
I have not passed webcams into VMs, so I cannot say if the passthrough should be automatic or not. I'm going to lean toward using a Virtualbox USB filter to put the Webcam into the VM instead of the Webcam passthrough feature, since USB filters will work automatically on many USB devices when the VM starts or the device is plugged in.
See
USB basics and troubleshooting
Re: How to auto connect to webcam in VirtualBox?
Posted: 4. Sep 2022, 20:34
by l-w-c
Do you mean like in this screenshot?
But:
- Doesn't it take place only when the USB device is plugged out and and in? What if it's plugged in all the time as most webcams tend to be?
- It didn't help me since it got it enabled under the USB menu and not under Webcams...worse still, it removed it from the Webcams menu! It seems you can't enable the same device under both USB and webcam.
Re: How to auto connect to webcam in VirtualBox?
Posted: 5. Sep 2022, 14:50
by scottgus1
l-w-c wrote:Doesn't it take place only when the USB device is plugged out and and in?
In my experience, a USB-Filtered device like a USB thumb drive will switch into the VM when the VM starts. The device has to be switchable, though, and not in use by the host OS at the time. This is discussed in the tutorial. If your Webcam falls into the switchable devices category, and it is not being used by the host OS at the time the VM starts, then it might switch into the VM automatically. Only time and experimentation will tell.
l-w-c wrote:it enabled under the USB menu and not under Webcams...worse still, it removed it from the Webcams
Yes. The device is being handled by the USB Filters, not by the Webcams menu. Since the USB Filter takes the device away from the host to put it into the VM, the cam is no longer on the host, so it is not seen by the Webcams menu. (Using the Webcams menu, the device remained attached to the host OS and the video was forwarded to the VM. With USB Filtering the device is moved to the VM completely; USB devices cannot be shared.)
Automatic switching was a condition of your request, so your workflow with the Webcam may change. If the USB Filter achieves the goal of automatic switching at VM start and device plug-in, you'd use the USB menu to switch the Webcam in and out of the VM while the VM is running, and not use the Webcam menu anymore.
Re: How to auto connect to webcam in VirtualBox?
Posted: 5. Sep 2022, 20:40
by l-w-c
Not sure I understand. If the webcam is enabled through the USB screen, then I can't use it, as programs just don't see it as a webcam.
Yet if the webcam is enabled through the Webcams screen, then it's usable but doesn't get enabled automatically.
How can I get it enabled automatically in the Webcams screen, so I can always use it?
Re: How to auto connect to webcam in VirtualBox?
Posted: 5. Sep 2022, 21:13
by scottgus1
l-w-c wrote:If the webcam is enabled through the USB screen, then I can't use it, as programs just don't see it as a webcam.
The VM's OS should see a USB Webcam in the USB devices, and the program in the VM should see this Webcam too. The VM OS needs drivers for the Webcam. See the troubleshooting step 8 and follow the instructions provided.
l-w-c wrote:How can I get it enabled automatically in the Webcams screen,
Will have to leave this question to others who use webcams a lot.
Re: How to auto connect to webcam in VirtualBox?
Posted: 5. Sep 2022, 22:32
by fth0
l-w-c wrote:How can I get it enabled automatically in the Webcams screen, so I can always use it?
Only by scripting the
VBoxManage controlvm <VM name> webcam attach command on the host side (see
9.5. Webcam Passthrough for details).
Re: How to auto connect to webcam in VirtualBox?
Posted: 5. Sep 2022, 23:35
by l-w-c
fth0 wrote:l-w-c wrote:How can I get it enabled automatically in the Webcams screen, so I can always use it?
Only by scripting the
VBoxManage controlvm <VM name> webcam attach command on the host side (see
9.5. Webcam Passthrough for details).
Can you please show me how (in Windows inside Windows)? It seems more fitting than settling for the webcam showing up under Devices in USB instead of Webcams, and somehow still making it work as a webcam against VirtualBox' own instructions.
Re: How to auto connect to webcam in VirtualBox?
Posted: 6. Sep 2022, 00:16
by fth0
l-w-c wrote:Can you please show me how (in Windows inside Windows)?
I think I've seen some scripts from
scottgus1 in other threads, which start a VM and wait for it to come up ...
Re: How to auto connect to webcam in VirtualBox?
Posted: 6. Sep 2022, 00:20
by l-w-c
fth0 wrote:l-w-c wrote:Can you please show me how (in Windows inside Windows)?
I think I've seen some scripts from
scottgus1 in other threads, which start a VM and wait for it to come up ...
Any links? Also, what if I plug the real webcam out then in again? I want the guest to pick up on that even if it already runs,
Re: How to auto connect to webcam in VirtualBox?
Posted: 6. Sep 2022, 15:53
by fth0
l-w-c wrote:Any links?
No, but I'll ping
scottgus1 in case he abandoned this thread.
l-w-c wrote:Also, what if I plug the real webcam out then in again?
I don't know what'll happen then. The suggested
VBoxManage command roughly does the same as the menu item, so you can answer your question yourself by trying it using the menu.
l-w-c wrote:I want the guest to pick up on that even if it already runs
This simply will not work with the current implementation of the Webcam Passthrough. But if you manually plug in/out the webcam, you can also manually trigger the corresponding action.
Re: How to auto connect to webcam in VirtualBox?
Posted: 6. Sep 2022, 16:03
by scottgus1
fth0 wrote:I think I've seen some scripts from scottgus1 in other threads, which start a VM and wait for it to come up ...
Yes, there does exist a way to start the VM and wait for the VM OS's desktop to load up, then run further commands on the host. But, as fth0 points out, this script won't cover the need to have the webcam go into the VM using the Webcam attach method whenever the Webcam is plugged in. The USB Filters method has better chance of making the automatic plug-in work. We have not seen any USB Basics tutorial diagnostic data from step 8 yet.
Re: How to auto connect to webcam in VirtualBox?
Posted: 7. Sep 2022, 22:00
by l-w-c
scottgus1 wrote:But, as fth0 points out, this script won't cover the need to have the webcam go into the VM using the Webcam attach method whenever the Webcam is plugged in.
What about running the scripts every couple of minutes?
The USB Filters method has better chance of making the automatic plug-in work. We have not seen any USB Basics tutorial diagnostic data from step 8 yet.
Just to clarify, let's say the USB menu way works, still won't the Webcam menu always be better?
Re: How to auto connect to webcam in VirtualBox?
Posted: 7. Sep 2022, 23:18
by scottgus1
l-w-c wrote:won't the Webcam menu always be better?
All theoretical at this point. Hard data is required to establish a solid answer. No hard data yet.
