Akheem Yousaf
Akheem Yousaf

Reputation: 1

How to get video streaming data in Apache nifi?

Could you please tell me, is there a way to get video streaming into Nifi? I am using Nifi "ExecuteProcess" to run python and OpenCV in order to capture the video stream but I am not able to make multiple flow files. My programs run the python code and then put all the captured frames in a single flow file. As I want to do analysis using YOLOV3 on live videos, I want each frame in a different flow file. The code is given below. My program runs the python code using "ExecuteProcess" and when the program finishes it stores everything that is on the output console to a single flow file but I want multiple flow files.

If there is a better way to get live video streaming using Nifi, please share it.

import cv2

cap = cv2.VideoCapture("videolink.mp4")

while (True):
    ret, image = cap.read()
    et, jpeg = cv2.imencode('.jpg', image)
    jp = jpeg.tobytes()
    print(jp)

cap.release()
cv2.destroyAllWindows() 

Upvotes: 0

Views: 1189

Answers (1)

daggett
daggett

Reputation: 28634

i think the simplest way to make streaming:

1/ setup ListenHTTP processor that will receive video parts through incoming POST requests. and this will become your data ingestion point.

2/ add to your python script http-post method call instead of print like this:

import cv2
import requests

cap = cv2.VideoCapture("videolink.mp4")

while (True):
    ret, image = cap.read()
    et, jpeg = cv2.imencode('.jpg', image)
    jp = jpeg.tobytes()
    # PORT and BASE_PATH must be configured in ListenHTTP processor
    requests.post('http://localhost:PORT/BASE_PATH', data = jp)
cap.release()
cv2.destroyAllWindows()

Upvotes: 0

Related Questions