diff --git a/bambulabs_api/camera_client.py b/bambulabs_api/camera_client.py index 8e93067..3c43dc4 100644 --- a/bambulabs_api/camera_client.py +++ b/bambulabs_api/camera_client.py @@ -1,5 +1,7 @@ #!/usr/bin/python3 +import cv2 + import base64 import struct import socket @@ -167,3 +169,25 @@ def retriever(self): time.sleep(5) logging.info("Reconnecting...") continue + + +class RTSPSCamera: + """Camera Client for X1""" + def __init__( + self, + hostname: str, + access_code: str, + port: int = 322, + username: str = 'bblp' + ) -> None: + self.rtsps_uri = f"rtsps://{username}:{access_code}@{hostname}:{port}/streaming/live/1" # noqa: E501 + + def start(self): + self.cap = cv2.VideoCapture(self.rtsps_uri) + + def get_frame(self): + _, frame = self.cap.read() + return frame + + def stop(self): + self.cap.release() diff --git a/environment.yml b/environment.yml index 4beee6b..4a23026 100644 --- a/environment.yml +++ b/environment.yml @@ -13,4 +13,5 @@ dependencies: - webcolors - pip: - paho_mqtt - - pillow \ No newline at end of file + - pillow + - opencv-python \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index b8bc951..a4d09e6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,6 +20,7 @@ classifiers = [ dependencies = [ "paho-mqtt>=2.0.0", "pillow>=11.0.0", + "opencv-python>=4.10.0", ] [project.urls] @@ -31,3 +32,4 @@ Issues = "https://github.com/BambuTools/bambulabs_api/issues" python = "^3.10" paho-mqtt = "^2.0.0" pillow = "^11.0.0" +opencv-python = "^4.10.0" diff --git a/requirements.txt b/requirements.txt index fd83fa3..72c0c2b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ sphinx_rtd_theme paho_mqtt webcolors pillow +opencv-python