import cv2
# 视频流地址
video_stream_url = "rtsp://admin:cc@ip:port/Streaming/Channels/502"
# 获取视频
video_capture = cv2.VideoCapture(video_stream_url)
# 视频帧率和总帧数
fps = video_capture.get(cv2.CAP_PROP_FPS)
total_frames = fps * 10
# 保存视频
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi', fourcc, fps, (int(video_capture.get(3)), int(video_capture.get(4))))
# 保存10秒视频和一帧图片
frame_count = 0
while frame_count < total_frames:
success, frame = video_capture.read()
if success:
out.write(frame)
if frame_count == 0:
cv2.imwrite("frame.jpg", frame)
frame_count += 1
else:
break
# 释放资源
video_capture.release()
out.release()
python脚本通过视频流获取图片和视频
最新推荐文章于 2024-10-18 15:04:24 发布
494

被折叠的 条评论
为什么被折叠?



