Opencv VideoCapture 未流式传输 RTSP 链接并返回“无帧!”

问题描述 投票:0回答:1

我正在尝试通过 python 传输我的 HikVision IP 摄像机。我正在使用

cv2.VideoCapture("rtsp_link")
,它在我的笔记本电脑上运行良好,但是当我尝试使用相同的 Opencv 和 FFmpeg 版本运行相同的 python 脚本时,它给出了以下错误:

错误:

[h264 @ 000002124c7f9a40] missing picture in access unit with size 47
[h264 @ 000002124c7f9a40] no frame!

到目前为止,我已尝试在 5 台计算机设备上运行此脚本,但它给出了相同的错误。我正在使用以下 python 脚本,我的 Opencv 版本是

4.6.0.66
和 ffmpeg 版本
2022-06-20-git-56419428a8-essentials_build-www.gyan.dev
:

Python 脚本:

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()

更新:

代码可以在笔记本电脑上通过 WiFi 和移动互联网 (4G) 运行,但在其他设备上只能通过移动互联网 (4G) 访问 rtsp 链接。

python opencv ffmpeg rtsp hikvision
1个回答
0
投票

您是否连接到同一网络?

© www.soinside.com 2019 - 2024. All rights reserved.