You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.0 KiB
38 lines
1.0 KiB
import logging
|
|
|
|
import cv2
|
|
print(cv2.__version__)
|
|
def open_video(video_id):
|
|
cap = cv2.VideoCapture(video_id)
|
|
if not cap.isOpened():
|
|
logging.info("无法打开摄像头")
|
|
exit()
|
|
return cap
|
|
|
|
|
|
rtsp_url ="rtsp://admin:123456abc@192.168.1.64:554/h264/ch1/main/av_stream"
|
|
capture = open_video(rtsp_url)
|
|
fps = capture.get(cv2.CAP_PROP_FPS)
|
|
width = int(capture.get(cv2.CAP_PROP_FRAME_WIDTH))
|
|
height = int(capture.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
|
print(f"fps={fps}")
|
|
print("width={width}, height={height}".format(width=width, height=height))
|
|
|
|
# 定义视频编码器和输出文件
|
|
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
|
out = cv2.VideoWriter('output.mp4', fourcc, fps, (width, height))
|
|
# 读取一帧图像
|
|
while True:
|
|
ret, frame = capture.read()
|
|
print("-->")
|
|
|
|
if ret:
|
|
# 写入帧到输出文件
|
|
out.write(frame)
|
|
else:
|
|
logging.info("无法读取帧")
|
|
if cv2.waitKey(1) & 0xFF == ord('q'): # 按'q'退出循环
|
|
break
|
|
|
|
capture.release()
|
|
out.release()
|
|
|