h264 frame to numpy array

asked 2014-01-16 05:38:08 -0500

martin gravatar image

Hello, I am new to opencv. using opecv-python.

I have created a rstp client in python that receives a h264 stream retunrns single h264 raw frames as a binary string . I am trying to process each frame on-the-fly.

I have unsuccessfully tried sever ways to convert this frame into a numpy array for processing.

So far I only know that cv2.VideoCapture only accepts a file name, not a frame neither a StringIO object (file like pointer to a buffer).

I have also tried something like:

nparr = np.fromstring(frame_bin_strg, np.uint8)

img_np = cv2.imdecode(nparr, cv2.CV_LOAD_IMAGE_COLOR)

but also miserably failed.

after many other failed attempts , I ran out of ideas.

To summarize what I need to do: I have a h264 raw frame in a variable and I need to create an openvc valid numpy array or a somehow end up with a VideoCapture object containing that single frame, so I can process the frame.

Any pointers would be much appreciated.

Hope this all makes sense.

Thank you in advance

edit retag flag offensive close merge delete