Closed brandoningli closed 3 years ago
Please try and run it in --akvcam
mode. You don't have to have installed akvcam for that. Do let me know if that helps.
Running it with --akvcam
causes weird image artifacting/duplication and an almost immediate segfault. akvcam is not installed on this machine.
Okay, maybe compiling a new version of v4l2loopback-dkms, or try installing the actual akvcam. It does appear that running it with --akvcam
causes the program to segfault.
Just built v4l2lopback following the instructions in the README, and I'm still getting segfaults.
I'll try giving akvcam an install.
Okay, try the following:
--akvcam
If segfault still happens, do let me know which webcam software you tried to use before it segfaults. Then do the followings:
--akvcam
--akvcam
Segfault has got more to do with the C library my Python code is calling, than my own Python code.
I've been using the Zoom desktop client and Jitsi Meet (via Firefox 89) to test (but not both programs at the same time).
ETA: It doesn't segfault when launching any program. It segfaults while using said program.
The results of doing the above:
-v
parameter to a v4l2loopback virtual camera,
$ python3 fake.py -w /dev/video2 --akvcam
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 "fake.py", line 421, in <module>
main()
File "fake.py", line 393, in main
cam = FakeCam(
File "fake.py", line 155, in __init__
self.fake_cam = AkvCameraWriter(v4l2loopback_path, self.width, self.height)
File "/home/brandon/Documents/git/Linux-Fake-Background-Webcam/akvcam.py", line 11, in __init__
self.d = self.open_camera()
File "/home/brandon/Documents/git/Linux-Fake-Background-Webcam/akvcam.py", line 24, in open_camera
ioctl(d, v4l2.VIDIOC_S_FMT, vid_format)
OSError: [Errno 22] Invalid argument
Exception ignored in: <function AkvCameraWriter.__del__ at 0x7ff99bd320d0>
Traceback (most recent call last):
File "/home/brandon/Documents/git/Linux-Fake-Background-Webcam/akvcam.py", line 32, in __del__
os.close(self.d)
AttributeError: 'AkvCameraWriter' object has no attribute 'd'
Giving a v4l2loopback virtual camera with `-v`, it's running, but the picture is showing weird artifacting (green and magenta, has horizontal bars, and is duplicated). It also segfaults.
I have an `akvcam` device with an informational graphic, but I don't know how to get the fake background webcam program to interface with it. I've never used this module before.
While this doesn't solve the segfault issue, I made a workaround to restart the script when it does. It produces a bit of a flash when the camera restarts (which can be quite frequently and very annoying), but otherwise starts back up very quickly and seems to work decently in the interim. Exiting with CTRL + \
produces a 0 exit code and this script ends gracefully.
#!/bin/bash
CODE=1
while [ "$CODE" -ne "0" ]; do
python3 /path/to/fake.py -w /dev/video2 -v /dev/video7 -i /path/to/image/folder
CODE=$?
done
You need to specify -v
with the akvcam
device. akvcam
adds two devices after your last webcam device. Whether or not you run it with AkvCameraWriter
is sort of irrelevant at this point. We just want to stop the segfault.
I can confirm that there's still a segfault running with akvcam
and the akvcam device, even segfaulting faster on average than using v4l2loopback
.
What's your operating system?
Pop!_OS 20.04 LTS. It's based on Ubuntu 20.04 LTS.
In that case I have no idea then. I will leave this ticket open.
@brandoningli , please give the latest commit a go. Please reconfigure akvcam based on the README.
When running fake.py, you need to set -v to the second video device that Akvcam created, e.g. if Akvcam created /dev/video5 and /dev/video6, you need to set -v /dev/video5.
Did you mean to say the first device or video6?
video 5, apologise. I will amend the README.
Also, is --akvcam
still required to be used? It's being reported as an unrecognized argument.
Nope, I completely removed that option.
Ok. It's still in the README, but not in the usage info in the program.
Done, updated README.
I'm still getting frequent segfaults, and my computer seems to crash completely 15-30 seconds afterwards. I have no way of directly blaming the script or akvcam, but it happens reliably after the segfault and rarely any other time.
Okay maybe try the Docker version? I suspect it is the difference between OS versions. It runs pretty stably on my Debian Stable
Has the docker version been updated to use mediapipe? I've used the older docker version before with success, but poor performance.
Someone supposedly patched the Dockerfile, and if you re-generate the Docker image, it should be up-to-date.
It has updated to the new mediapipe implementation, but there's two issues with the Docker implementation:
akvcam.py
which doesn't exist anymore. I can submit that in a PR shortly.Okay, definitely submit your PR.
I think I am just going to leave this issue open. I can't suggest any ways for you to fix it. I don't know if vanilla Ubuntu 20.04 would have the same problem.
Thanks for your help, though!
@brandoningli , could you give this a go please on normal v4l2loopback-dkms
please? I suspect this might be some sort of race condition going on.
https://github.com/fangfufu/Linux-Fake-Background-Webcam/tree/single-threaded
I don''t want to jinx it, but it's already been running longer without segfaulting than any other version. I'll leave it running in the background for a while and report back if it segfaults or keeps running. Performance seems on-par with the regular mediapipe version before it segfaulted as well.
Basically I tried to add more multithreading, and I tried putting the mask generation within the RealCam
class. I kept getting segfaults myself too. This led to the suspicion of race conditions. Race condition is not exactly easy to diagnose, especially I don't really use Python enough. I wonder if this race condition was introduced after I removed all the async
stuff.
But if this patch works, then I will merge it to master.
Ah, race conditions. Gotta love them.
It's been running stably for me now for about ten minutes, which is much longer than before the patch. If it was going to segfault, it would've by now.
Hold that thought. When stopping, I got this error:
Traceback (most recent call last):
File "fake.py", line 380, in <module>
main()
File "fake.py", line 377, in main
cam.run()
File "fake.py", line 286, in run
frame = self.compose_frame(frame)
File "fake.py", line 258, in compose_frame
frame[:, :, c] = frame[:, :, c] * mask + background_frame[:, :, c] * (1 - mask)
File "fake.py", line 344, in sigquit_handler
cam.stop()
File "fake.py", line 274, in stop
self.real_cam.stop()
AttributeError: 'RealCam' object has no attribute 'stop'
Thank you so much for helping out!
@brandoningli , btw, if you need help with job applications / Masters applications / PhD course applications, feel free to ping me an email. I saw on your Github profile that you are open for work.
Also, what's your CPU, if you don't mind me asking.
Intel i5-6300HQ (4) @ 3.200GHz
While running, I get an average of 19-20fps at 720p, which is much better than previous versions getting single-digit frame rates at that resolution.
However, after running for a minute or two, the program produces a Segmentation fault and stops. I'm able to restart the script and it picks right back up, but again Seg faults after a minute or two.
Pop!_OS (Ubuntu) 20.04 Kernel 5.11.0-7614-generic Project just pulled minutes ago. Python 3.8.5
v4l2loopback-dkms
version 0.12.3-1ubuntu0.4 (from repos). I haven't yet tried compiling from source, but can if requested. Pip Package versions:Program output: