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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I make this into a service?

RemyFV opened this issue · comments

thanks for your tool, Fangfufu! it works great and it's literally the only one that does so without much hassle :)

I have been looking for a way to make it into a background service that would start when I log in, so that it's always available (since it's paused when unused).

do you have any recommendation for this? my venture into systemd was unsuccessful.

Nope, I don't have any suggestions on how to do this, and I don't recommend you do this either. To be honest, I am really surprised to hear you want to do this, considering how unstable it can be - sometimes the instability is not even my problem (#127).

Add this to /etc/udev/rules.d/webcam.rules to create systemd bind devices for /dev/videoX system devices.

KERNEL=="video0", SYMLINK="video0", TAG+="systemd"
KERNEL=="video1", SYMLINK="video1", TAG+="systemd"

do it for as much devices as needed.

Then, for instance ~/.config/sytemd/user/fakecam.service:

[Unit]
Description=Linux Fake Background Webcam
BindsTo=dev-video0.device
After=dev-video0.device
BindsTo=dev-video1.device
After=dev-video1.device

[Service]
Type=simple
ExecStart=/full/path/to/fake.py

[Install]
WantedBy=default.target

Again add BindsTo= and After= to as many video devices as you need.

The ExecStart depends on how you have the project installed, you can use %h to indicate the user's home directory if you need.

Personally, I have it setup using a python virtualenv so I actually call a wrapper script I called fakecam:

#!/usr/bin/env sh

cwd=$PWD
cd /full/path/to/Linux-Fake-Background-Webcam || exit
. ./env/bin/activate
./fake.py
deactivate
cd "$cwd" || exit

And I use that in ExecStart instead.

that is cool, thank you very much.

I'll see if it breaks my laptop over time :)

@ruifm , thanks a lot! If you have any scripts / tips on setting up venv, please submit a pull request, or opening up an issue. I plan to work on it later, I just haven't got around to do it yet.

@RemyFV , it is not going to break your laptop over time. Personally I find it easier to run it in a terminal. So I know when things break down.

@ruifm , @RemyFV , please share your OS version, v4l2loopback version, Python version, Mediapipe version, Numpy version, if you don't mind. There are other users who experience stability issues. I think they would appreciate these info.

I'm on debian 12, v4l2loopback from repo so 0.12.5 I guess. I'll check the rest out tomorrow and come back to you.

it's very stable for me - went on 30m 1h calls without any issues. the only little problem I have is that I need to set the threshold to something like 5 to get a usable picture even with my actual green screen background, but I'm more than understanding here.

the hologram filter makes it look cool, even :)

@ruifm If you have any scripts / tips on setting up venv, please submit a pull request, or opening up an issue. I plan to work on it later, I just haven't got around to do it yet.

Imo setting up a python venv is such a simple thing it does not warrant special docs, but maybe I do not represent the majority. A simple comprise would be suggesting setting up a venv and linking to the arch wiki on how to do it but that decision is up to you, I'm not good on writing user docs 😉

@ruifm , @RemyFV , please share your OS version, v4l2loopback version, Python version, Mediapipe version, Numpy version, if you don't mind. There are other users who experience stability issues. I think they would appreciate these info.

Well, I'm not experiencing any stability issues but ok:

  • os: archlinux (kernel 5.12.13)
  • v4l2loopback: 0.12.5-1 v4l2loopback-dmks from archlinux repos
  • python: 3.9.6 (system python)
  • mediapipe: 0.8.7.1 (from just using a python venv and running pip -r requirements.txt)
  • numpy: 1.21.2 (same origin as mediapipe)

@RemyFV , I am very surprised that you need to change threshold and you have an actual green screen. It works reasonably well in my cluttered background, until I hang up my washings. It thinks my clothes is an actual person.

the camera on my Thinkpad T480s is bad and my lighting isn't that good either. I'll send you some before / after pictures in a PM, you'll tell me if it looks normal to you !

Debian 12 Bookworm, kernel 5.10.0-8-amd64
v4l2loopback 0.12.5 (from the official github repository)
Python 3.9.7 (from debian 12 repository, not 100% sure)
mediapipe 0.8.7.1
numpy 1.19.5 (both from pip -r requirements.txt)

I sent you a mail with screenshots for the threshold thing!