11from urllib .parse import urlparse
22import logging
3- # Issue with opencv-python and homeassistant
4- # try:
5- # # Verify that the OpenCV python package is pre-installed
6- # import cv2
7- # CV2_IMPORTED = True
8- # except ImportError:
9- # CV2_IMPORTED = False
103
114from hikvision_isapi_cli .client import Client
5+ from hikvision_isapi_cli .api .isapi import channels_1_picture
126
137_LOGGER = logging .getLogger (__name__ )
148
@@ -21,54 +15,22 @@ def __init__(self, client: Client, rtsp_port: int, path: str) -> None:
2115 :param rtsp_port: The RTSP port of the stream.
2216 :param path: The path of the stream.
2317 """
24- # if not CV2_IMPORTED:
25- # _LOGGER.error(
26- # "No OpenCV library found! Install or compile for your system "
27- # "following instructions here: http://opencv.org/releases.html"
28- # )
29- # return
30-
18+
3119 self .client = client
3220 self .rtsp_port = rtsp_port
3321 self .path = path
3422 self .host = urlparse (client .base_url ).hostname
3523 self .stream_url = (
3624 f"rtsp://{ client .username } :{ client .password } @{ self .host } :{ rtsp_port } /{ path } "
3725 )
38- # self.cap = cv2.VideoCapture(self.stream_url)
39- # self.cap.set(cv2.CAP_PROP_BUFFERSIZE, 60)
40- # self.cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*"H264"))
4126
42- def get_snapshot (self ) -> bytes :
27+ def get_snapshot (self , channel_id : int ) -> bytes :
4328 """
4429 Capture a snapshot from the RTSP stream and return the binary data of the image.
4530
4631 :return: The binary data of the image, or None if the frame cannot be read.
4732 """
48- # ret, frame = self.cap.read()
49- # if ret:
50- # # Encode the image as JPEG
51- # _, img_encoded = cv2.imencode(".jpg", frame)
52- # # Return the binary data
53- # return img_encoded.tobytes()
54- # else:
55- # # Return None if the frame cannot be read
56- # return None
57- raise NotImplementedError ()
58-
59- def release (self ):
60- """
61- Release the RTSP stream.
62- """
63- #self.cap.release()
64- raise NotImplementedError ()
65-
66- def open (self ):
67- """
68- Open the RTSP stream.
69- """
70- #self.cap.open(self.stream_url)
71- raise NotImplementedError ()
33+ return channels_1_picture .sync_detailed (channel_id = channel_id ,client = self .client ).content
7234
7335 def stream_source (self ) -> str :
7436 """
0 commit comments