I am trying to stream my HikVision IP camera throough python. I am using cv2.VideoCapture("rtsp_link")
which works fine on my Laptop but when I try to run the same python script with same Opencv and FFmpeg version it gives me following error:
Error:
[h264 @ 000002124c7f9a40] missing picture in access unit with size 47
[h264 @ 000002124c7f9a40] no frame!
I have so far tried to run this script on 5 computer devices but it gives the same error. I am using the following python script and my Opencv version is 4.6.0.66
and ffmpeg version 2022-06-20-git-56419428a8-essentials_build-www.gyan.dev
:
Python Script:
import cv2
# RTSP stream URL
rtsp_url = "rtsp://username:password@ip_address:port/Streaming/Channels/501"
# Open the RTSP stream
cap = cv2.VideoCapture(rtsp_url)
# Check if the stream was successfully opened
if not cap.isOpened():
print("Failed to open RTSP stream.")
exit()
# Read and display frames from the stream
while True:
# Read a frame from the stream
ret, frame = cap.read()
# Check if the frame was successfully read
if not ret:
print("Failed to read frame from RTSP stream.")
break
# Display the frame
cv2.imshow("RTSP Stream", frame)
# Exit if 'q' is pressed
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Release the resources
cap.release()
cv2.destroyAllWindows()
Update:
Code runs on a laptop on both wifi and mobile internet (4G) but on other devices rtsp link is accessible only with mobile internet (4G).