37 lines
991 B
Python
37 lines
991 B
Python
|
import cv2
|
||
|
import subprocess
|
||
|
|
||
|
rtsp = "rtsp://admin:2020@uestc@192.168.30.83:554/h264"
|
||
|
out_rtsp = 'rtsp://localhost:5001/test'
|
||
|
|
||
|
# 读取视频并获取属性
|
||
|
cap = cv2.VideoCapture(rtsp)
|
||
|
size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
|
||
|
sizeStr = str(size[0]) + 'x' + str(size[1])
|
||
|
fps = cap.get(cv2.CAP_PROP_FPS)
|
||
|
command = ['ffmpeg',
|
||
|
'-y', '-an',
|
||
|
'-f', 'rawvideo',
|
||
|
'-vcodec', 'rawvideo',
|
||
|
'-pix_fmt', 'bgr24',
|
||
|
'-s', sizeStr,
|
||
|
'-r', str(fps),
|
||
|
'-i', '-',
|
||
|
'-c:v', 'libx264',
|
||
|
'-pix_fmt', 'yuv420p',
|
||
|
'-preset', 'ultrafast',
|
||
|
'-f', 'rtsp',
|
||
|
out_rtsp]
|
||
|
|
||
|
pipe = subprocess.Popen(command, shell=False, stdin=subprocess.PIPE)
|
||
|
|
||
|
while cap.isOpened():
|
||
|
success, frame = cap.read()
|
||
|
if success:
|
||
|
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||
|
break
|
||
|
pipe.stdin.write(frame.tostring())
|
||
|
|
||
|
cap.release()
|
||
|
pipe.terminate()
|