# -*- coding:utf-8 -*- # @Time : 2021/12/31 16: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 class RtstPushServer: def __init__(self, fps=25,width=1080,height=960,rtsp='rtsp://192.168.1.182:8554/video'): print('fps=',fps,' weitht=',width,' height=',height,' rtsp=',rtsp) #此处换为你自己的地址 self.lrtsp_url =rtsp # Get video information self.lfps = fps self.lwidth = width self.lheight = height self.command = ['ffmpeg', '-y', '-f', 'rawvideo', '-vcodec', 'rawvideo', '-pix_fmt', 'bgr24', '-s', "{}x{}".format(self.lwidth, self.lheight), '-r', str(self.lfps), '-i', '-', '-c:v', 'libx264', # '-c:v', 'libx265', '-pix_fmt', 'yuv420p', '-preset', 'ultrafast', '-f', 'rtsp', self.lrtsp_url] self.p = sp.Popen(self.command, stdin=sp.PIPE) def write(self,frame): if frame is None: print("frame is None") return # frame = 你的图像处理的函数(frame) self.p.stdin.write(frame.tostring()) # cv2.imshow('img',frame) # if cv2.waitKey(1) == ord('q'): # q to quit # raise StopIteration