-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
34 lines (28 loc) · 941 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import cv2
import subprocess as sp
rtsp_server = 'rtsp://65.2.75.34:8554/mystream'
cap = cv2.VideoCapture(0)
sizeStr = str(int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))) + 'x' + str(int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
fps = int(cap.get(cv2.CAP_PROP_FPS))
command = ['ffmpeg',
'-re',
'-s', sizeStr,
'-r', str(fps), # rtsp fps (from input server)
'-i', '-',
'-pix_fmt', 'yuv420p',
'-r', '30', # output fps
'-g', '50',
'-c:v', 'libx264',
'-b:v', '2M',
'-bufsize', '64M',
'-maxrate', "4M",
'-preset', 'veryfast',
'-rtsp_transport', 'tcp',
'-segment_times', '5',
'-f', 'rtsp',
rtsp_server]
process = sp.Popen(command, stdin=sp.PIPE)
while (cap.isOpened()):
ret, frame = cap.read()
ret2, frame2 = cv2.imencode('.png', frame)
process.stdin.write(frame2.tobytes())