- Apache Kafka Cluster Setup - Follow this
- Create an instance outside Kafka Cluster with Docker binaries installed
docker pull ajeetraina/opencv4-python3
docker run -itd -p 5000:5000 ajeetraina/opencv4-python3 bash
docker attach <container-id>
git clone https://github.com/collabnix/pico
cd pico/kafka/
If in case it reports that pico already exists, remove it first and then try the above command. I still need to package it properly.
Two entries needed to be changed:
- topic name(which you must have supplied during the initial Kafka cluster configuration)
- bootstrapper server IP pointing to your Kafka Broker
import sys
import time
import cv2
# from picamera.array import PiRGBArray
# from picamera import PiCamera
from kafka import KafkaProducer
from kafka.errors import KafkaError
topic = "testpico"
def publish_video(video_file):
"""
Publish given video file to a specified Kafka topic.
Kafka Server is expected to be running on the localhost. Not partitioned.
:param video_file: path to video file <string>
"""
# Start up producer
producer = KafkaProducer(bootstrap_servers='10.140.0.2:9092')
def publish_camera():
"""
Publish camera video stream to specified Kafka topic.
Kafka Server is expected to be running on the localhost. Not partitioned.
"""
# Start up producer
producer = KafkaProducer(bootstrap_servers='10.140.0.2:9092')
Download a sample video and rename it as Countdown1.mp4. Place it here in the same directory where producer and consumer resides.
python producer.py
Open up consumer script and modify the two important items:
- Topic Name: testpico
- Bootstrap Server: :9093
Executing the Script
python consumer.py
By now you can browse through http://:5000 to see video streaming.