import cv2
# video = cv2.VideoCapture("rtsp://192.168.0.200:554/av0_0")
video = cv2.VideoCapture("fire.mp4")
# 获取视频帧数
frame_count = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
# 获取fps,每秒传输帧数(Frames per second)
fps = int(round(video.get(cv2.CAP_PROP_FPS)))
# 分辨率-宽度
width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))
# 分辨率-高度
height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))
print(f'视频帧数:{frame_count}')
print(f'FPS:{fps}')
print(f'Width:{width}')
print(f'Height:{height}')
# delay表示延迟多少毫秒进入下一帧
delay = int(1000 / fps)
while video.isOpened():
# ret是布尔值,如果读取帧是正确的则返回True,如果文件读取到结尾,它的返回值就为False。frame是每一帧的图像,是个三维矩阵。
ret, frame = video.read()
if frame is None:
break
if ret == True:
cv2.imshow("result", frame)
# waitKey(delay):表示一帧等待delay毫秒在进入下一帧,期间如果有按键按下返回的值就是按下按键的ASCII值; 27 = esc; & 0xFF只是为了排除键盘上其他按键的干扰
if cv2.waitKey(delay) & 0xFF == 27:
break
# 释放视频
video.release()
cv2.destroyAllWindows()
标签:视频,get,int,frame,cv2,delay,OpenCV,video,使用
From: https://www.cnblogs.com/smalldong/p/17900215.html