白云岛资源网 Design By www.pvray.com
我就废话不多说了,直接上代码吧!
# 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实时码流按时生成连续视频文件方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
白云岛资源网 Design By www.pvray.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
白云岛资源网 Design By www.pvray.com
暂无评论...