您好,登錄后才能下訂單哦!
我就廢話不多說了,直接上代碼吧!
# coding: utf-8 import datetime import cv2 import os ip = '192.168.3.160'.replace(".", "_") rtsp = 'rtsp://admin:admin@192.168.3.160:554/1/1' # 初始化攝像頭 cap = cv2.VideoCapture(rtsp) fourcc = cv2.VideoWriter_fourcc(*'XVID') size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))) frame_count = 0 while cap.isOpened(): isSuccess, frame = cap.read() if isSuccess: if frame_count % 120 == 0 or frame_count == 0: frame_count = 0 i = datetime.datetime.now().strftime("%Y%m%d%H%M%S") filename = str(i) + '-' + ip + '.avi' print(filename) video_writer = cv2.VideoWriter(filename, fourcc, 24, size) video_writer.write(frame) frame_count = frame_count + 1 print(frame_count) if frame_count % 120 == 0: video_writer.release() portion = os.path.splitext(filename) newname = portion[0] + '.mp4' os.rename(filename, newname) cv2.imshow('show', frame) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()
效果
以上這篇python cv2讀取rtsp實時碼流按時生成連續視頻文件方式就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。