yolo_standard_libray/011python拉去ffmpeg流.py
2025-03-07 11:35:40 +08:00

20 lines
487 B
Python

import cv2
video_path = 'rtsp://10.0.0.17:8554/camera_test/2'
cap = cv2.VideoCapture(video_path)
i = 0
while True:
ret, frame = cap.read()
if not ret:
print("Can't receive frame (stream end?). Exiting ...")
break
# 这里的编码会将 frame 拉成 一维数组。
# ret, jpeg_frame = cv2.imencode('.jpg', frame)
cv2.imwrite(f'upload_{i}.jpg', frame)
i += 1
if i == 5:
break
cap.release()
cv2.destroyAllWindows()