This is a simple Python script that shows live stream video of an RTSP stream. RTSP is a protocol and is short for Real Time Streaming Protocol.
Prepare IP camera with RTSP
For this post, I used a Wyze v2 camera which had the RTSP firmware installed. I installed the RTSP firmware, known as demo.bin from the Wyze website.
Get RTSP URL
Now that you have your RTSP camera ready, enable the RTSP live video URL. It will be of this format:
rtsp://USERNAME:PASSWORD@IPADDRESS/ENDPOINT
where USERNAME, PASSWORD, IPADDRESS and ENDPOINT will vary depending on your values.
Create script wyzelive.py
Copy my script wyzelive.py
to a directory of your choice.
#!/usr/bin/env python # -*- coding: utf-8 -*- """ This Python script shows Wyze v2 cam live using the RTSP link Author : Arul John Created : Updated : """ import cv2 # RTSP info -- change these 4 values according to your RTSP URL username = 'USERNAME' password = 'PASSWORD' endpoint = 'ENDPOINT' ip = 'IPADDRESS' # Stream stream = cv2.VideoCapture(f'rtsp://{username}:{password}@{ip}/{endpoint}') try: while True: # Read the input live stream ret, frame = stream.read() height, width, layers = frame.shape frame = cv2.resize(frame, (width // 2, height // 2)) # Show video frame cv2.imshow("Wyze v2 camera", frame) # Quit when 'x' is pressed if cv2.waitKey(1) & 0xFF == ord('x'): break except Exception as e: print("ERROR:", e) # Main function if __name__ == "__main__": # Release and close stream stream.release() cv2.destroyAllWindows()
Edit wyzelive.py and replace the four values with your own values.
You may not have the Python module cv2
in your Python environment. Let's install cv2
.
pip install cv2
Now that the dependencies are installed, run the script:
python wyzelive.py
You will see a live video using your camera. To quit, press x
and the program will stop.
Stay tuned for follow-up posts.
Please let me know if you run into any issues. Thanks for reading this post.
Related Posts
If you have any questions, please contact me at arulbOsutkNiqlzziyties@gNqmaizl.bkcom. You can also post questions in our Facebook group. Thank you.