pyfakewebcam icon indicating copy to clipboard operation
pyfakewebcam copied to clipboard

OSError: [Errno 22] Invalid argument fcntl.ioctl

Open saifrahmed opened this issue 4 years ago • 10 comments

Dear @jremmons - Firstly thanks for this project, this is exactly what I was looking for!

I tried running the project (both pip installed and via local pulls (both tagged release and master branch) but keep getting and "OSError: [Errno 22] Invalid argument" on the fcntl.ioctl call.

I tried using both webcams w/o success. I also did a ls /dev | grep video and tried the different devices w/o success.

Suspecting an issue with the settings object _v4l2.v4l2_format() I also tried to strip that down w/o success. I'm running on Ubuntu 18 with all the required dependency installs. Any suggestions on possible ways to debug this?

Traceback (most recent call last):
    camera = pyfakewebcam.FakeWebcam('/dev/video20', 640, 480)
  File "/home/sahmed/WORKSPACE/scantrac/ctnr-fakecam/pyfakewebcam/pyfakewebcam.py", line 54, in __init__
    fcntl.ioctl(self._video_device, _v4l2.VIDIOC_S_FMT, self._settings)
OSError: [Errno 22] Invalid argument

saifrahmed avatar Apr 12 '20 18:04 saifrahmed

I'm running into the same issue on Mint 19.3:

Traceback (most recent call last):
  File "webtest.py", line 11, in <module>
    camera = pyfakewebcam.FakeWebcam('/dev/video20', 640, 480)
  File "/usr/local/lib/python3.6/dist-packages/pyfakewebcam-0.1.0-py3.6.egg/pyfakewebcam/pyfakewebcam.py", line 56, in __init__
    fcntl.ioctl(self._video_device, _v4l2.VIDIOC_S_FMT, self._settings)
OSError: [Errno 22] Invalid argument

enteryournamehere avatar Apr 15 '20 09:04 enteryournamehere

its seems Proposed solution was to install the kernel module from github instead of using the officially distributed v4l2-loopback package from Ubuntu 18.04

https://github.com/umlaeute/v4l2loopback/issues/172

jjenly avatar Apr 15 '20 21:04 jjenly

That seems to fix it, thanks!

enteryournamehere avatar Apr 16 '20 21:04 enteryournamehere

Ubuntu 18.04 Linux 5.3.0-46-generic

#remove apt package sudo modprobe -r v4l2loopback sudo apt remove v4l2loopback-dkms

#install aux sudo apt-get install linux-generic sudo apt install dkms

#install v4l2loopback from the repository https://github.com/umlaeute/v4l2loopback.git cd v4l2loopback make

#instal mod sudo cp -R . /usr/src/v4l2loopback-1.1 sudo dkms add -m v4l2loopback -v 1.1 sudo dkms build -m v4l2loopback -v 1.1 sudo dkms install -m v4l2loopback -v 1.1 sudo reboot

pedrodiamel avatar Apr 20 '20 15:04 pedrodiamel

Do you happen to know if these steps are relevant for Ubuntu 20.04? Thanks!

bgeels avatar Oct 14 '20 22:10 bgeels

Using video2 instead of video1 worked for me. (Ubuntu 20.04)

cahidenes avatar Nov 16 '20 19:11 cahidenes

I have the same problem with Ubuntu 21.04. (I have already tried all mentioned fixes). Any ideas?

Alwinator avatar May 03 '21 16:05 Alwinator

I have the same problem with Ubuntu 21.04. (I have already tried all mentioned fixes). Any ideas?

Do sudo modprobe -r v4l2loopback

see the output of ls /dev/video*

In your modprobe command choose a virtual device number that is not already present.

In my case I used modprobe v4l2loopback devices=1 exclusive_caps=1 video_nr=7 card_label="v4l2loopback"

With 7 being an id that was not existing prior to activating v4l2loopback.

JanSurft avatar May 12 '21 11:05 JanSurft

@JanSurft Thanks a lot! Now it works! I think the explicit phrase of the video ID did the trick.

sudo modprobe -r v4l2loopback
sudo modprobe v4l2loopback devices=1 exclusive_caps=1 video_nr=7 card_label="v4l2loopback"
ls /dev/video*

image

Alwinator avatar May 12 '21 15:05 Alwinator

@JanSurft Thanks a lot! Now it works! I think the explicit phrase of the video ID did the trick.

sudo modprobe -r v4l2loopback
sudo modprobe v4l2loopback devices=1 exclusive_caps=1 video_nr=7 card_label="v4l2loopback"
ls /dev/video*

image

For me, it was /dev/video20. Why does that happen, and can I set the number manually to 2?

WickedWizard3588 avatar Aug 13 '21 04:08 WickedWizard3588