How to turn the laptop built-in webcam on/off from shell

3

Fn+F6 key combination turns my laptop's integrated web camera on/off. Looking at the dmesg output, it seems that the webcam (USB device) is being more or less virtually connected/disconnected to/from the USB bus:

usb 1-5: new high-speed USB device number 9 using ehci_hcd
usb 1-5: New USB device found, idVendor=5986, idProduct=0203
usb 1-5: New USB device strings: Mfr=3, Product=1, SerialNumber=0
usb 1-5: Product: BisonCam, NB Pro
usb 1-5: Manufacturer: Bison Electronics Inc.
uvcvideo: Found UVC 1.00 device BisonCam, NB Pro (5986:0203)
input: BisonCam, NB Pro as /devices/pci0000:00/0000:00:1d.7/usb1/1-5/1-5:1.0/input/input14
usb 1-5: USB disconnect, device number 9

The first seven lines come after "connect" and the last line is after "disconnect" event. dmesg timestamps removed for clarity.

showkey executed from a tty console returned keycode 214, xev from KDE returned keycode 220 and also XF86WebCam. Here's the part of xev output related to pressing the Fn+F6:

KeyPress event, serial 40, synthetic NO, window 0x3600001,
    root 0xac, subw 0x0, time 78270130, (346,354), root:(348,377),
    state 0x0, keycode 220 (keysym 0x1008ff8f, XF86WebCam), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

I've already tried sending the keycode of the Fn+F6 combination (either 214, 220 or XF86WebCam) using the xdotool, xvkbd and xmacro, but with no success.

Probably the right way to do it is not by using the keycodes at all.

sm4rk0

Posted 2013-02-23T22:53:04.790

Reputation: 615

I had to reboot to Win7 and hit Fn+F6 to re-enable my camera (don't know what disabled it in the first place) and then reboot back into Ubuntu. Would love to have a "Ubuntu-only" solution. – copper.hat – 2014-07-06T20:09:37.460

Note: I don't have a real-life use case for this. It's just my curiosity (: So, no workarounds like disabling/enabling the driver and/or the USB hub are of any help. – sm4rk0 – 2013-02-23T23:57:33.847

Answers

2

You may be able to do this using modprobe interactively on the command line. You may be able to blacklist it and then reboot or resource in /etc/modprobe.d/blacklist.conf

I just found this post on AskUbuntu which may provide some more detail, since I don't have a system up with a webcam in front of me at the moment.

Eric G

Posted 2013-02-23T22:53:04.790

Reputation: 1 010

Thanks for the answer. Just tried it, but as I suspected, this doesn't help. It would only work if the webcam was already switched on, but if webcam is off this method won't turn it on. For a webcam to work at least two conditions must be met: (webcam on) AND (driver loaded). The post from AskUbuntu deals with the second and I'm interested in the first "switch". – sm4rk0 – 2013-02-23T23:17:35.520

I think the keyboard shortcut with the function keys maybe be outside the scope of the operating system's control. I would imagine you would want it switched on in hardware, and then by default have it blacklisted, turning it on manually (?) – Eric G – 2013-02-23T23:21:34.583

Maybe it would work one-way: to turn on the webcam, but if a process is currently using it, you can't remove the webcam's driver. Another solution would be sudo echo -n "0000:00:1d.7" > /sys/bus/pci/drivers/ehci_hcd/unbind to disable and sudo echo -n "0000:00:1d.7" > /sys/bus/pci/drivers/ehci_hcd/bind to enable the USB port the webcam is connected to. This is what I use to "reset" the webcam if it hangs. Note: this also temporarily disconnects other devices that may be connected to the same hub! The card reader in my case. – sm4rk0 – 2013-02-23T23:53:24.943

Correction: Disabling ehci_hcd puts all of the High-Speed (2.0) USB devices into Full-Speed (1.1) mode. It does not disable the USB hub. – sm4rk0 – 2013-02-24T01:12:16.840

1

Run this command with root permissions:

echo 0 > /sys/devices/pci0000:00/0000:00:1d.7/usb1/1-5/1-5:1.0/authorized

The path is taken from dmesg's output:

input: BisonCam, NB Pro as /devices/pci0000:00/0000:00:1d.7/usb1/1-5/1-5:1.0/input/input14

This will forbid the system to have access to your device without deactivating neither the whole bus nor the uvc driver, and no reboot required.

To reactivate, run echo 1 > /sys/devices/pci0000:00/0000:00:1d.7/usb1/1-5/1-5:1.0/authorized (again with root permissions).

Note: I use Archlinux with Linux 4.17

ilspinoza

Posted 2013-02-23T22:53:04.790

Reputation: 11