import cv2
import time

# 获取 ezopen 协议的 URL
url = "rtmp://rtmp03open.ys7.com:1935/v3/openlive/L05874022_1_1?expire=1726487667&id=625419662355599360&t=228dca5d37b6bead201e80cca3fc5fe74140242278e4eb51a99bcce593cae027&ev=100"

# 创建 VideoCapture 对象
cap = cv2.VideoCapture(url)

cv2.namedWindow("Video", cv2.WINDOW_NORMAL)  # Create a named window
cv2.resizeWindow("Video", 640, 384)          # Resize this window

start_time = time.time()
count = 0

# 获取视频帧
while True:
    ret, frame = cap.read()
    if time.time() - start_time < 1:  # 循环运行直到1秒过去
        count += 1
    else:
        print(count)
        start_time = time.time()
        count = 0

    # print(ret)
    if not ret:
        print("Error read video stream.")
        break
    # 显示视频帧
    cv2.imshow("Video", frame)
    # print("0000000000000",ret)
    # 等待用户按下任意键退出
    key = cv2.waitKey(1)
    if key == 27:
        break

# 释放资源
cap.release()
cv2.destroyAllWindows()
