# -*- coding:utf-8 -*- # @Time : 2021/12/3010:17 # @Author : lxc # @File : tortsp.py # https://github.com/aler9/rtsp-simple-server import cv2 import subprocess as sp import signal import numpy as npbool #此处换为你自己的地址 rtsp_url = 'rtsp://192.168.1.182:8554/video' cap = cv2.VideoCapture("rtsp://admin:hk123456@192.168.1.65:554") # Get video information fps = int(cap.get(cv2.CAP_PROP_FPS)) width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) command = ['ffmpeg', '-y', '-f', 'rawvideo', '-vcodec', 'rawvideo', '-pix_fmt', 'bgr24', '-s', "{}x{}".format(width, height), '-r', str(fps), '-i', '-', # '-c:v', 'libx264', '-c:v', 'libx265', '-pix_fmt', 'yuv420p', '-preset', 'ultrafast', '-f', 'rtsp', rtsp_url] p = sp.Popen(command, stdin=sp.PIPE) while (cap.isOpened()): ret, frame = cap.read() frame=cv2.resize(frame,(1080,640)) if not ret: print("Opening camera is failed") break # frame = 你的图像处理的函数(frame) p.stdin.write(frame.tostring()) # cv2.imshow('img',frame) # if cv2.waitKey(1) == ord('q'): # q to quit # raise StopIteration