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

Question: how to tweak for reduced lag on old laptop?

katakombi opened this issue · comments

Hi,

I've installed this nice piece of SW and I am pleasantly surprised how well it worked out of the box for me.
I've got an old i5-3320M with integrated gfx so pretty low-end. I see an avg of 7fps and a CPU utilization of 50% on one of both cores.

I've got a time lag between 1-2secs. Is there a way to trim this down at the sake of let's say resolution and/or fps? Also CPU utilization could be higher?

I'll go on tweaking but meanwhile maybe those more experienced would be so kind and share their suggestions?

thanks a lot and have a nice weekend!

Update: I've tested now with my external FHD web cam and I get 10fps with 100% CPU utilization. The lag is around 1sec now. I would be satisfied with the most simple background removal or substitution option possible if just I could workaround this lag

You could try the multithreaded version, and reduce webcam resolution.

Thanks, I wasn't aware of the multithread branch. This actually really helps I am getting up to 15fps now. Lowering resolution leads to errors so I am afraid my cam doesn't support it. For some reason the process dies after a couple of minutes with a segfault (happens also in single thread)

dmesg says

[457121.469723] python3[379132]: segfault at b8 ip 00000000005d1769 sp 00007ffe082e1b80 error 4 in python3.8[423000+293000]
[457121.469752] Code: 00 00 48 83 c4 08 5b 5d 41 5c 41 5d 41 5e 41 5f c3 48 8b 47 08 48 81 78 30 40 16 5d 00 0f 85 37 02 00 00 48 8b 1d 6f a4 36 00 <8b> 8b b8 00 00 00 83 f9 31 0f 8f 35 02 00 00 83 c1 01 89 8b b8 00

There is another ticket saying that multhreaded version has race condition: #116

There isn't anything else I could do suggest, other than lowering the resolution.

Thanks, yes, I've found that issue shortly after. Gonna follow up on this one. For some reason I get crashes also with single threading but maybe this is due to another bug.

@katakombi , disabling foreground replacement also helps.

@katakombi , disabling foreground replacement also helps.

Yeah this brings it up to 30fps with almost no delay. Why is that? Isn't the foreground replacement supposed to be just an overlay? This should not have any effect on the performance, no?

Wait what?! 30 fps Without foreground replacement?! I have to test this out then!

Basically with foreground replacement, it does a bunch more matrix maths.

https://github.com/fangfufu/Linux-Fake-Background-Webcam/blob/master/fake.py#L287

I don't observe the same effect, if you are 100% certain that disabling foreground overlay helps, then please do confirm it. Preferably with some statistics.

Sure, just have a look there
https://asciinema.org/a/EB8YzpTJw1rsgGazLv6L0VTZO
For some reason I don't observe now a 30fps improvement - either it is different now or I confused it. Still a gain 15->22 which looks oddly high to me. I can do some more measurements if you like.

The figures you posted on Asciinema fits within my own observation. I think it is just that matrix maths on CPU is expensive.

The figures you posted on Asciinema fits within my own observation. I think it is just that matrix maths on CPU is expensive.

Sure. Maybe this could be optimized by using OpenGL operations instead? For me it is most important to know how to obtain the speed I need. I have no requirement for foreground mapping really so having >20fps is very nice although there must not be anything else producing load at the same time.

Yeh, I am sort of looking into this. I don't have much experience with OpenGL though, especially with Python.

I now tried it once again and this left me confused:
https://asciinema.org/a/upauUvfVyRnGpRedtZxllc7DU

First of all: shouldn't be --no--background --no--foreground be slower than just --no-foreground?
Second: I am pretty sure there was nothing running the background.
BTW I am utilizing v4l2loopback

I am very confused too. This is bad.

As stated before if you need more systematic testing I can run them and provide you with the stats you need

I don't really need more systematic testing - it is a known issue. But feel free to post some stats, if you are bored.

I just didn't know it is that bad. Also, I reckon it is heavily affected by what you run in the background too. OpenCV probably uses those matrix instructions which can easily clog up the CPU pipeline.

If that's the case the OGL offloading could really be helpful. Maybe you could look out for a blender dev to help out with that?
Thanks for your magnificent work... I will keep using fake-cam for testing purposes.

@katakombi , if you are good with Python and etc, please have a look at: #121. I have posted some initial starting points.

@katakombi , could the fluctuation in FPS due to the lighting condition of the room? If it is too dark, the real webcam cannot get to high FPS.

Yeah thats absolutely possible.