fangfufu / Linux-Fake-Background-Webcam

Faking your webcam background under GNU/Linux, now supports background blurring, animated background, colour map effect, hologram effect and on-demand processing.
GNU General Public License v3.0
1.61k stars 161 forks source link

Errno 22 when video-call app (or on browser) is opened before running fake.py. (Resolved by system reboot) #196

Closed firepainting closed 1 year ago

firepainting commented 1 year ago

Hi. First of all fake-cam is awesome! Thanks to everyone that made this possible! Second, please be patient, I'm not that proficient in Linux things even though I got this to work somehow. Thanks!

Okay, so just to be clear, fake-cam works on my end and it works very well IMO. But I have to run it first (python3 fake.py -c .config-fake-cam.ini) before opening any video-call app. Otherwise, if I mistakenly open the app or browser before running fake.py, I get the error below.

How do I resolve this without having to restart my laptop?

This is true for/reproducible with:

I only did the v4l2loopback route (did not need to try Akvcam).

Many thanks in advance!

INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Real camera original values are set as: 640x480 with 30 FPS and video codec 1448695129
Real camera new values are set as: 1280x720 with 30 FPS and video codec 1196444237
Traceback (most recent call last):
  File "/home/firepainting/fake.py", line 557, in <module>
    main()
  File "/home/firepainting/fake.py", line 546, in main
    cam = FakeCam(args)
  File "/home/firepainting/fake.py", line 130, in __init__
    self.fake_cam = pyfakewebcam.FakeWebcam(self.v4l2loopback_path, self.width,
  File "/home/firepainting/.local/lib/python3.10/site-packages/pyfakewebcam/pyfakewebcam.py", line 54, in __init__
    fcntl.ioctl(self._video_device, _v4l2.VIDIOC_S_FMT, self._settings)
OSError: [Errno 22] Invalid argument

My .config-fake-cam.ini:

width = 1280
height = 720
fps = 30
; no-background = yes
background-keep-aspect = no
no-foreground = yes
threshold = 50
background-image = "/home/firepainting/Downloads/sample_bg_fake_cam.jpg"
v4l2loopback-path = /dev/video2
webcam-path = /dev/video3
System:
  Kernel: 5.15.0-87-generic x86_64 bits: 64 compiler: gcc v: 11.4.0
    Desktop: Cinnamon 5.8.4 Distro: Linux Mint 21.2 Victoria
    base: Ubuntu 22.04 jammy
Machine:
  Type: Laptop System: LENOVO product: 81G2 v: Lenovo ideapad 330-14IKB
    serial: <superuser required>
  Mobo: LENOVO model: LNVNB161216 v: SDK0K13455 WIN
    serial: <superuser required> UEFI-[Legacy]: LENOVO v: 8KCN47WW
    date: 10/16/2018
CPU:
  Info: dual core model: Intel Core i3-7020U bits: 64 type: MT MCP
    arch: Coffee Lake rev: A cache: L1: 128 KiB L2: 512 KiB L3: 3 MiB
  Speed (MHz): avg: 800 min/max: 400/2300 cores: 1: 800 2: 800 3: 800
    4: 800 bogomips: 18399
  Flags: avx avx2 ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx
Graphics:
  Device-1: Intel HD Graphics 620 vendor: Lenovo driver: i915 v: kernel
    bus-ID: 00:02.0
  Device-2: Logitech Webcam C270 type: USB driver: snd-usb-audio,uvcvideo
    bus-ID: 1-1.2:6
  Device-3: Chicony EasyCamera type: USB driver: uvcvideo bus-ID: 1-8:4
  Display: x11 server: X.Org v: 1.21.1.4 driver: X: loaded: modesetting
    unloaded: fbdev,vesa gpu: i915 resolution: 1366x768~60Hz
  OpenGL: renderer: Mesa Intel HD Graphics 620 (KBL GT2)
    v: 4.6 Mesa 23.0.4-0ubuntu1~22.04.1 direct render: Yes
Network:
  Device-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet
    vendor: Lenovo driver: r8169 v: kernel port: 3000 bus-ID: 01:00.0
  IF: enp1s0 state: down mac: <filter>
  Device-2: Qualcomm Atheros QCA9377 802.11ac Wireless Network Adapter
    vendor: Lenovo driver: ath10k_pci v: kernel bus-ID: 02:00.0
  IF: wlp2s0 state: up mac: <filter>
Info:
  Processes: 257 Uptime: 23m Memory: 7.54 GiB used: 2.65 GiB (35.1%)
  Init: systemd runlevel: 5 Compilers: gcc: 11.4.0 Packages: 2587 Shell: Bash
  v: 5.1.16 inxi: 3.3.13
fangfufu commented 1 year ago

If you terminate the app, that uses your real webcam, it should work.

firepainting commented 1 year ago

@fangfufu Thanks and sorry for this late reply.

Do you mean quitting the app (e.g., Zoom), then running python3 fake.py -c .config-fake-cam.ini? That does not work.

firepainting commented 1 year ago

I'm trying to install Akvcam but it won't install the driver.

/$ ls /lib/modules/$(uname -r)/extra/akvcam.ko*
ls: cannot access '/lib/modules/5.15.0-87-generic/extra/akvcam.ko*': No such file or directory
firepainting@firepainting:~$ cd akvcam/src

firepainting@firepainting:~/akvcam/src$ make
make -C /usr/lib/modules/5.15.0-87-generic/build M=/home/firepainting/akvcam/src  modules
make[1]: Entering directory '/usr/src/linux-headers-5.15.0-87-generic'
  CC [M]  /home/firepainting/akvcam/src/module.o
  CC [M]  /home/firepainting/akvcam/src/attributes.o
  CC [M]  /home/firepainting/akvcam/src/buffers.o
  CC [M]  /home/firepainting/akvcam/src/controls.o
  CC [M]  /home/firepainting/akvcam/src/device.o
  CC [M]  /home/firepainting/akvcam/src/driver.o
  CC [M]  /home/firepainting/akvcam/src/file_read.o
  CC [M]  /home/firepainting/akvcam/src/format.o
  CC [M]  /home/firepainting/akvcam/src/frame.o
  CC [M]  /home/firepainting/akvcam/src/frame_filter.o
  CC [M]  /home/firepainting/akvcam/src/ioctl.o
  CC [M]  /home/firepainting/akvcam/src/list.o
  CC [M]  /home/firepainting/akvcam/src/log.o
  CC [M]  /home/firepainting/akvcam/src/map.o
  CC [M]  /home/firepainting/akvcam/src/rbuffer.o
  CC [M]  /home/firepainting/akvcam/src/settings.o
  CC [M]  /home/firepainting/akvcam/src/utils.o
  LD [M]  /home/firepainting/akvcam/src/akvcam.o
  MODPOST /home/firepainting/akvcam/src/Module.symvers
  CC [M]  /home/firepainting/akvcam/src/akvcam.mod.o
  LD [M]  /home/firepainting/akvcam/src/akvcam.ko
  BTF [M] /home/firepainting/akvcam/src/akvcam.ko
Skipping BTF generation for /home/firepainting/akvcam/src/akvcam.ko due to unavailability of vmlinux
make[1]: Leaving directory '/usr/src/linux-headers-5.15.0-87-generic'

firepainting@firepainting:~/akvcam/src$ sudo make dkms_install
[sudo] password for firepainting:                   
dkms remove akvcam/1.2.4 --all
Error! The module/version combo: akvcam-1.2.4 is not located in the DKMS tree.
make: [Makefile:63: dkms_uninstall] Error 3 (ignored)
rm -rvf /usr/src/akvcam-1.2.4
rm -rvf /usr/src/akvcam-1.2.4
mkdir -p /usr/src/akvcam-1.2.4
cp -f Makefile /usr/src/akvcam-1.2.4
cp -f dkms.conf /usr/src/akvcam-1.2.4
cp -f *.h /usr/src/akvcam-1.2.4
cp -f *.c /usr/src/akvcam-1.2.4
dkms install akvcam/1.2.4
Creating symlink /var/lib/dkms/akvcam/1.2.4/source -> /usr/src/akvcam-1.2.4

Kernel preparation unnecessary for this kernel. Skipping...

Building module:
cleaning build area...
make -j4 KERNELRELEASE=5.15.0-87-generic KERNEL_DIR=/lib/modules/5.15.0-87-generic/build all....
Signing module:
 - /var/lib/dkms/akvcam/1.2.4/5.15.0-87-generic/x86_64/module/akvcam.ko
EFI variables are not supported on this system
/sys/firmware/efi/efivars not found, aborting.
cleaning build area...

akvcam.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/5.15.0-87-generic/updates/dkms/

depmod.....
firepainting commented 1 year ago

Well, I'm not sure if I missed something on the instructions and if this is the case for everyone else, but a workaround I found is by unloading the v4l2loopback module and re-laoding it back: sudo modprobe -r v4l2loopback && sudo modprobe v4l2loopback

That frees me from the need to reboot after an "Errno 22", but is it normal/okay to unload and re-load it like that?

I'm using the v4l2loopback from the github repository.

fangfufu commented 1 year ago

The error message came from not being able to start the fake webcam. I am not sure what caused that problem.

firepainting commented 1 year ago

Thanks. At least I get it to work now without rebooting my laptop. Can get by with restarting apps and reloading the module. That's good enough for me!