jashandeep-sohi / webcam-filters

Add filters (background blur, etc) to your webcam on Linux.
GNU General Public License v3.0
551 stars 16 forks source link

Caps object is not iterable #34

Open jekkos opened 3 years ago

jekkos commented 3 years ago

When running webcam-filters I get the following traceback

➜  ~ webcam-filters --verbose --input-dev /dev/video0 --output-dev /dev/video3 --background-blur 150

Traceback (most recent call last):
  File "/home/restore/.local/bin/webcam-filters", line 9, in <module>
    sys.exit(main())
  File "/home/restore/.local/lib/python3.8/site-packages/webcam_filters/__main__.py", line 5, in main
    cli.main(prog_name="webcam-filters")
  File "/home/restore/.local/lib/python3.8/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/home/restore/.local/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/restore/.local/lib/python3.8/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/home/restore/.local/lib/python3.8/site-packages/webcam_filters/main.py", line 154, in cli
    add_filters(
  File "/home/restore/.local/lib/python3.8/site-packages/webcam_filters/gst.py", line 98, in add_filters
    for s in caps:
TypeError: 'Caps' object is not iterable

I tried different devices but always the same result. Anything else I can check?

jashandeep-sohi commented 3 years ago

What happens when you do a webcam-filters --list-dev-caps /dev/video0 (or whichever /dev/videoX is your actual webcam)?

jekkos commented 3 years ago

I get the same message in fact. I double checked if I can change some setting on this device, it seems fine.

sudo v4l2-ctl --set-ctrl=exposure_absolute=90 -d /dev/video0 this works

➜  ~ webcam-filters --list-dev-caps /dev/video0                  
<Gst.Caps object at 0x7f382db4f100 (GstCaps at 0x26e9940)>
Traceback (most recent call last):
  File "/home/restore/.local/bin/webcam-filters", line 9, in <module>
    sys.exit(main())
  File "/home/restore/.local/lib/python3.8/site-packages/webcam_filters/__main__.py", line 5, in main
    cli.main(prog_name="webcam-filters")
  File "/home/restore/.local/lib/python3.8/site-packages/click/core.py", line 1061, in main
    with self.make_context(prog_name, args, **extra) as ctx:
  File "/home/restore/.local/lib/python3.8/site-packages/click/core.py", line 923, in make_context
    self.parse_args(ctx, args)
  File "/home/restore/.local/lib/python3.8/site-packages/click/core.py", line 1379, in parse_args
    value, args = param.handle_parse_result(ctx, opts, args)
  File "/home/restore/.local/lib/python3.8/site-packages/click/core.py", line 2364, in handle_parse_result
    value = self.process_value(ctx, value)
  File "/home/restore/.local/lib/python3.8/site-packages/click/core.py", line 2326, in process_value
    value = self.callback(ctx, self, value)
  File "/home/restore/.local/lib/python3.8/site-packages/webcam_filters/gst.py", line 369, in print_device_caps
    for c in caps:
TypeError: 'Caps' object is not iterable
jashandeep-sohi commented 3 years ago

Did you install all of the system dependencies? Specifically, is gst-python installed and what version? #5 is similar and they needed python3-gst-1.0 on Ubuntu.

If that doesn't fix it or you run into other dependency issues, I'd recommend installing with https://github.com/jashandeep-sohi/webcam-filters#nix. There are too many variations in gstreamer dependencies between distros, and I've found Nix to be the best way to ensure everyone's working with the same versions.

hs-neax commented 3 years ago

I'm having the same issue on an up-to-date arch: gst-python 1.18.5-1 gstreamer 1.18.5-1 Python 3.9.7

jekkos commented 3 years ago

Ok the error went away after running

sudo apt install python3-gst-1.0

can be closed, thx

jekkos commented 3 years ago

Wait, now I'm seeing this error

Error from /GstPipeline:pipeline0/GstV4l2Sink:v4l2sink0: Could not open device '/dev/video2' for reading and writing.

my video2 device is a virtual one created by v4l2 loopback. Any idea why this is?

jashandeep-sohi commented 3 years ago

Wait, now I'm seeing this error

Error from /GstPipeline:pipeline0/GstV4l2Sink:v4l2sink0: Could not open device '/dev/video2' for reading and writing.

my video2 device is a virtual one created by v4l2 loopback. Any idea why this is?

@jekkos

What are the kernel mod parameters you created this device with?

To rule out if this is a problem with webcam-filters can you run the following basic gstreamer pipeline:

gst-launch-1.0 -v v4l2src device=/dev/video0 ! videoconvert ! video/x-raw, format=YUY2 ! v4l2sink device=/dev/video2
jashandeep-sohi commented 3 years ago

I'm having the same issue on an up-to-date arch: gst-python 1.18.5-1 gstreamer 1.18.5-1 Python 3.9.7

@hs-neax Is gst-plugins-base and gst-plugins-good also installed?

hs-neax commented 3 years ago

@jashandeep-sohi: Yes they are. Don't know whats causing it. I created a Dockerfile instead, since I considered that more useful as an alternative to nix than fixing user system specific stuff. Maybe it'd be worth adding that to the repo with an a bit more generalized start.sh.

Dockerfile

FROM ubuntu:impish

ENV DEBIAN_FRONTEND="noninteractive" 
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    python3.9 \
    python3-pip \
    python3-gi python3-gi-cairo gir1.2-gtk-3.0 \
    gstreamer1.0-plugins-good gstreamer1.0-plugins-base-apps gstreamer1.0-x python3-gst-1.0 gstreamer1.0-python3-plugin-loader

RUN pip install --pre webcam-filters

COPY start.sh .

CMD ["/bin/bash","start.sh"]

start.sh

#!/bin/bash

webcam-filters --input-dev /dev/video0 --output-dev /dev/video10 --background-blur 150

$ docker run --device=/dev/video0:/dev/video0 --device=/dev/video10:/dev/video10 webcam-filters

DmitrySandalov commented 3 years ago

Please add Ubuntu installation instructions to README.md

jashandeep-sohi commented 3 years ago

Apologies for the delayed response.

@hs-neax Happy to discuss any contributions in a PR. My reasoning for using Nix vs Docker was to have as "native" an experience as possible without having to mount any devices into a container run by the docker daemon (as root). It's been flaky for me in the past.

I don't mind adding a Dockerfile if that makes life easier, but I'm not sure I want to maintain a parallel file with dependencies for installing this. If possible, I'd prefer it if the Dockerfile also installed it using Nix or the container was built using Nix. And then CI can just push the image out to a public repository.

@DmitrySandalov Sounds good! I did pin #11, but it's probably a good idea to add that to the README.

hs-neax commented 2 years ago

@jashandeep-sohi: Sorry for the big delay. I understand your point about maintenance and made PR with a simple Docker container wrapping a Nix installation. I'm using it for a while now and it's working well.

sboehringer commented 1 year ago

I get the same error on openSUSE Tumbleweed 20221124. All dependencies seem to be installed.

Could you please post a command line equivalent of a pipeline produced by the package?