写入 rtsp 视频流
# 从本地设备获取视频 ffmpeg -i /dev/video0 -rtsp_transport tcp -f rtsp rtsp://192.168.xxx.xxx:xxx/test # 从视频文件获取 ffmpeg -re -i ./1.mp4 -vcodec copy -rtsp_transport tcp -f rtsp rtsp://192.168.xxx.xxx:xxx/test
rtsp 读取视频流
# coding=utf-8 import time VIDEO_PATH = "rtsp://192.168.xxx.xxx:xxx/test" def extract_frames(video_path): import cv2 video = cv2.VideoCapture(video_path) while True: _, frame = video.read() if frame is None: time.sleep(0.5) print("wait 0.5 second to retry...") else: cv2.imshow("Frame", frame) if cv2.waitKey(1) & 0xFF == ord('q'): break if __name__ == '__main__': extract_frames(VIDEO_PATH)