producer.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:Simple-stream-Kafka 作者: amwaleh 项目源码 文件源码
def video_emitter(video):
    # Open the video
    video = cv2.VideoCapture(video)
    print(' emitting.....')

    # read the file
    while (video.isOpened):
        # read the image in each frame
        success, image = video.read()

        # check if the file has read the end
        if not success:
            break

        # convert the image png
        ret, jpeg = cv2.imencode('.png', image)
        # Convert the image to bytes and send to kafka
        producer.send_messages(topic, jpeg.tobytes())
        # To reduce CPU usage create sleep time of 0.2sec
        time.sleep(0.2)
    # clear the capture
    video.release()
    print('done emitting')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号