You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.3 KiB
46 lines
1.3 KiB
3 years ago
|
# -*- coding:utf-8 -*-
|
||
|
# @Time : 2021/11/4 10:17
|
||
|
# @Author : JulyLi
|
||
|
# @File : rtsp2.py
|
||
|
# @Software: PyCharm
|
||
|
|
||
|
import cv2
|
||
|
|
||
|
import sys
|
||
|
import json
|
||
|
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', 'libx265',
|
||
|
'-pix_fmt', 'yuv420p',
|
||
|
'-preset', 'ultrafast',
|
||
|
'-f', 'rtsp',
|
||
|
rtsp_url]
|
||
|
p = sp.Popen(command, stdin=sp.PIPE)
|
||
|
|
||
|
while (cap.isOpened()):
|
||
|
ret, frame = cap.read()
|
||
|
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
|