-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream.py
55 lines (46 loc) · 1.63 KB
/
stream.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import cv2
import sockTest
import os
import muxing_py
print('vefore create obj')
stream_obj = muxing_py.Stream()
print('object created')
cam2 = 'rtmp://localhost/myapp/monkey'
cap = cv2.VideoCapture()
cap.open(cam2)
overlay = None
#fourcc = cv2.VideoWriter_fourcc(*'XVID')
#out = cv2.VideoWriter('outstream.avi',fourcc, 20.0, (1092, 614))
counter = 0
countStop = 0
time = 0
a = 0
while(cap.isOpened()):
#os.system("gnome-terminal -e 'bash -c \"ffmpeg -re -i /home/settnozz/python_stream/outstream.avi -c:v libx264 -preset veryfast -maxrate 3000k -bufsize 6000k -pix_fmt yuv420p -g 50 -c:a aac -b:a 160k -ac 2 -ar 44100 -f flv rtmp://live.twitch.tv/settnozz/live_64609648_vOa0jBYpxpYNbE0HoXjlf8ENxNDwLK; exec bash\"'")
ret, frame = cap.read()
if frame is None:
continue
maybeImage, time, x, y = sockTest.maybeNewImage()
if maybeImage is not None and time is not None and x is not None and y is not None:
overlay = maybeImage
IKS = x
IGR = y
print (time)
countStop = time
if overlay != None and countStop != None and IKS != None and IGR != None:
counter +=1
h2, w2 = overlay.shape[:2]
frame[IKS:h2 + IKS , IGR:w2 + IGR, :] = overlay
if counter == countStop:
overlay, countStop, counter, IKS, IGR = None, 0, 0, 0, 0
#out.write(frame)
gray_image = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
print('before write stream')
stream_obj.write_and_decode(gray_image)
print('after write stream')
cv2.imshow('frame', gray_image)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
#out.release()
cv2.destroyAllWindows()