import cv2
import time
import os.path
import datetime
url = "rtsp://admin:a123456789@192.168.1.22/Streaming/Channels/1"
#rtsp://用户名:密码@ip地址/Streaming/Channels/1最后面的1是因为我选择1会显示出我要的内容,有的是1或者3或者4
cap = cv2.VideoCapture(url)
ret, frame = cap.read()
while ret:#不断的刷新 ret=Trueret, frame = cap.read()cv2.imshow("frame",frame)file = "D:/pic/{}.jpg".format(datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S"))#以日期来命名文件并指定文件夹if(os.path.isfile(file)== False and int(time.strftime("%S",time.localtime()))%5==0):#每5s截图cv2.imwrite(file, frame, [int(cv2.IMWRITE_JPEG_QUALITY), 100])#无损输出图片 但是图片质量仍不是很高if cv2.waitKey(1) & 0xFF == ord('q'):#按q退出break
cv2.destroyAllWindows()#全屏显示
cap.release()#关闭