-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathproducer.py
37 lines (27 loc) · 867 Bytes
/
producer.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
import time
import sys
import cv2
from kafka import KafkaProducer
from kafka.errors import KafkaError
producer = KafkaProducer(bootstrap_servers='localhost:9092')
topic = 'my-topic'
def emit_video(path_to_video):
print('start')
video = cv2.VideoCapture(path_to_video)
while video.isOpened():
success, frame = video.read()
if not success:
break
# png might be too large to emit
data = cv2.imencode('.jpeg', frame)[1].tobytes()
future = producer.send(topic, data)
try:
future.get(timeout=10)
except KafkaError as e:
print(e)
break
print('.', end='', flush=True)
emit_video(0)
# zero is for open webcam or usb webcam
# can play a video just add video file in emit_video function
# rtsp camera stream add rtsp feed in emit_video function