Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle video access error cleanly #3

Closed
guyfawcus opened this issue May 3, 2020 · 2 comments
Closed

Handle video access error cleanly #3

guyfawcus opened this issue May 3, 2020 · 2 comments

Comments

@guyfawcus
Copy link

Use-case

  • Have an application that's using the video open (e.g. Zoom)
  • Open camset
  • Not have the logs be full of:
VIDIOC_S_FMT: failed: Device or resource busy
Traceback (most recent call last):
  File "/home/me/build/camset/env/lib/python3.6/site-packages/camset/camset.py", line 232, in on_output_combo_changed
    start_camera_feed(list[0], list[1], list[2], list[3])
  File "/home/me/build/camset/env/lib/python3.6/site-packages/camset/camset.py", line 30, in start_camera_feed
    subprocess.run(['v4l2-ctl', '-d', card, '-v', 'height={0},width={1},pixelformat={2}'.format(vfeedheight, vfeedwidth, pixelformat)], check=True, universal_newlines=True)
  File "/usr/lib/python3.6/subprocess.py", line 438, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['v4l2-ctl', '-d', '/dev/video0', '-v', 'height=1080,width=1920,pixelformat=']' returned non-zero exit status 255.

Fix

Simply adding a try/except around:

subprocess.run(['v4l2-ctl', '-d', card, '-v', 'height={0},width={1},pixelformat={2}'.format(vfeedheight, vfeedwidth, pixelformat)], check=True, text=True)

For example:

try:
    subprocess.run(['v4l2-ctl', '-d', card, '-v', 'height={0},width={1},pixelformat={2}'.format(vfeedheight, vfeedwidth, pixelformat)], check=True, universal_newlines=True)
except subprocess.CalledProcessError:
    print("It's okay!")

results in:

VIDIOC_S_FMT: failed: Device or resource busy
It's okay!

Going forward

Maybe it could check to see if an error occurs, and if it does, not open the video feed.
Also, might be worth considering not opening up the video feed by default on open?

azeam added a commit that referenced this issue May 3, 2020
@azeam
Copy link
Owner

azeam commented May 3, 2020

Added a check for busy resource. It will now silently fail and not open the feed window if the resource is busy, and show a warning dialog if pressing the show feed button when the device is busy. Added to pip as version 0.0.6.

I'm keeping the default behavior of opening the feed window if there are no issues though, it's got to do with the GTK combobox - if there are multiple resources the video should change when changing the device, and when setting the default device in the combobox at start it counts as changing = whatever I want to occur when changing a device will also occur when starting the application (if setting a default device at start, which I prefer).

I did however notice some things I need to fix with the warning dialog after pushing this, will improve that another day.

@guyfawcus
Copy link
Author

That's perfect! Just installed v0.0.6 and after changing the fourcc code (#2) it works like a charm 🥳

The default behavior is fine now - I open it up while Zoom has the feed and it doesn't try to open the video window or complain.

Love open source! Thanks again for your work on this 👊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants