-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathVideo_server_websocket.py
More file actions
38 lines (25 loc) · 981 Bytes
/
Video_server_websocket.py
File metadata and controls
38 lines (25 loc) · 981 Bytes
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
#!/usr/bin/env python
# WS server that sends camera streams to a web server using opencv
import asyncio
import websockets
import cv2
async def time(websocket, path):
while True:
camera = True
if camera == True:
vid = cv2.VideoCapture(0)
else:
vid = cv2.VideoCapture('videos/video1.mp4')
try:
while(vid.isOpened()):
img, frame = vid.read()
frame = cv2.resize(frame, (640, 480))
encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 65]
man = cv2.imencode('.jpg', frame, encode_param)[1]
#sender(man)
await websocket.send(man.tobytes())
except :
pass
start_server = websockets.serve(time, "127.0.0.1", 9997)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()