Skip to content

fix: no cam detected on Arch Linux, use string path for camera capture instead#1783

Open
Vito-M wants to merge 1 commit intohacksider:mainfrom
Vito-M:fix/arch-linux-camera-fix
Open

fix: no cam detected on Arch Linux, use string path for camera capture instead#1783
Vito-M wants to merge 1 commit intohacksider:mainfrom
Vito-M:fix/arch-linux-camera-fix

Conversation

@Vito-M
Copy link
Copy Markdown

@Vito-M Vito-M commented Apr 23, 2026

On the latest version of Arch Linux, the camera was no longer being detected at startup, causing the application to fail to list any available capture devices.

The fix passes the device path as a string (e.g. /dev/video0) directly, which resolves the issue on Arch Linux while preserving the existing behavior on other platforms (Windows/macOS).

Summary by Sourcery

Update Linux camera handling to open devices via their /dev/videoN path instead of numeric indices and keep existing behavior for other platforms.

Bug Fixes:

  • Ensure cameras are correctly detected and opened on recent Arch Linux systems by passing explicit /dev/videoN paths to OpenCV.

Enhancements:

  • Refine platform-specific video capture setup to distinguish Linux device-path usage from macOS auto-detection behavior.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Apr 23, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR fixes camera detection on Linux by switching OpenCV capture initialization to use explicit /dev/videoN string paths on Linux both when starting capture and when probing for available cameras, while preserving the existing auto-detection behavior on macOS and not affecting Windows logic.

Sequence diagram for Linux camera detection in get_available_cameras

sequenceDiagram
    actor User
    participant UI as UI_layer
    participant Cam as get_available_cameras
    participant CV2 as cv2

    User ->> UI: Open camera selection
    UI ->> Cam: get_available_cameras()
    Cam ->> Cam: Detect platform
    Cam ->> Cam: platform != Windows and platform == Linux
    loop Probe first 10 indices
        Cam ->> CV2: VideoCapture(/dev/video{i})
        CV2 -->> Cam: cap object
        Cam ->> CV2: cap.isOpened()
        CV2 -->> Cam: True/False
        alt cap is opened
            Cam ->> Cam: Append i to camera_indices
            Cam ->> Cam: Append Camera i to camera_names
        end
    end
    Cam -->> UI: camera_indices, camera_names
    UI -->> User: Display list of detected cameras
Loading

Flow diagram for Linux camera start logic in video_capture.start

flowchart TD
    A[start] --> B[Check platform.system]
    B --> C{platform == Windows}
    C -->|Yes| D[Use DirectShow or existing Windows capture logic]
    C -->|No| E{platform == Linux}
    E -->|Yes| F[Create cv2.VideoCapture with path /dev/video{device_index}]
    E -->|No| G[Create cv2.VideoCapture with device_index for macOS]
    F --> H{cap exists and cap.isOpened}
    G --> H
    D --> H
    H -->|No| I[Raise RuntimeError Failed to open camera]
    H -->|Yes| J[Return True]
    I --> K[end]
    J --> K
Loading

File-Level Changes

Change Details Files
Use explicit /dev/videoN string paths for OpenCV camera capture on Linux to restore device detection.
  • Update Unix-like camera start logic to special-case Linux and pass a /dev/video{index} string to cv2.VideoCapture
  • Keep non-Linux (macOS) path using the existing numeric device index to preserve current behavior
modules/video_capture.py
Align Linux camera enumeration with new device path approach when detecting available cameras.
  • Change Linux camera scanning loop to open /dev/video{i} via string paths when probing the first 10 camera indices
modules/ui.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The else branch in video_capture.start is labeled as macOS-specific but will also run on any other non-Windows, non-Linux Unix platforms; consider making the macOS check explicit (e.g. platform.system() == 'Darwin') or updating the comment to reflect the actual behavior.
  • For Linux, you now assume /dev/video{index} exists both when opening and probing cameras; adding an os.path.exists check (or similar) before constructing/using the device path would avoid unnecessary VideoCapture attempts on non-existent devices and make failures easier to reason about.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `else` branch in `video_capture.start` is labeled as macOS-specific but will also run on any other non-Windows, non-Linux Unix platforms; consider making the macOS check explicit (e.g. `platform.system() == 'Darwin'`) or updating the comment to reflect the actual behavior.
- For Linux, you now assume `/dev/video{index}` exists both when opening and probing cameras; adding an `os.path.exists` check (or similar) before constructing/using the device path would avoid unnecessary `VideoCapture` attempts on non-existent devices and make failures easier to reason about.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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

Successfully merging this pull request may close these issues.

1 participant