Mehul Purohit
Mehul Purohit

Reputation: 26

cv2.VideoCapture isn't read video coming from frontend

@app.route('/process', methods=['POST'])
def process():
    if request.method == 'POST':
        vid = request.files['file']
        cap = cv2.VideoCapture(vid)
        while(cap.isOpened()):
            ret,frame = cap.read()
            if not ret:
                break

            do_something()

            k = cv2.waitKey(1)
            if k == 27:
                break

I am sending a video from frontend to flask server to process it. But when I run this code, this error shows up on line cap = cv2.VideoCapture(vid):

TypeError: an integer is required (got type FileStorage)

The video coming is converted in class 'werkzeug.datastructures.FileStorage' and cv2.VideoCapture isn't accepting input as this class. What should I do?

I tried to save the video on local system using vid.save('abc.webm') and then read it using cv2.VideoCapture and it works perfectly. But I don't want to save it on system.

Please help. Thank you in advance.

Upvotes: 1

Views: 1757

Answers (1)

Cliff F
Cliff F

Reputation: 391

What you want is .read() to get the bytes from the FileStorage object.

vid = request.files['file'].read()
cap = cv2.VideoCapture(vid)

Upvotes: 1

Related Questions