How to decode video which I get from POST method with OpenCV?

asked 2020-06-02 07:55:58 -0500

balfad gravatar image

updated 2020-06-02 07:56:54 -0500

I am writing a Python backend for an Android app with Flask. I get video from POST method (when I do this: print(request.files['video'].read()) I get "d3\xb9}\xff\x04\xa4M\xef\x8fS\xc1\xf0\x9e:|ge\x1cfO\xc1\x11ry\x0b\xea\xd1\x82\xf2\xa9-H..."). I can convert it to numpy array by doing this np.frombuffer(request.files['video'].read(), np.uint8), but I don't know how I can decode it so that I can then process it with OpenCV. Can you please help me?

edit retag flag offensive close merge delete

Comments

read doc imdecode

LBerger gravatar imageLBerger ( 2020-06-02 08:52:10 -0500 )edit

@LBerger isn't it only for images and not for videos?

balfad gravatar imagebalfad ( 2020-06-02 11:43:00 -0500 )edit

since it's a video, not an image, write it to disk, and decode with VideoCapture later

berak gravatar imageberak ( 2020-06-02 11:43:19 -0500 )edit

imdecode() would work for a MJPG stream

berak gravatar imageberak ( 2020-06-02 11:44:22 -0500 )edit