2

So I need to read a video source (a file/stream) frame by frame and than, send each frame over the internet in real time. The issues is that when I'm using OpenCV VideCapture it returns numpy arrays which are difficult to handle (a frame can take up to 20 Mb, but when I save it as png it's around 300kb). (it would be cool if using some flag VideCapture could return bytes instead of numpy array )

The question is, how can I read a video source as raw bytes, so I don't need to convert numpy to bytes in case of using OpenCV.

1
  • numpy array is a fast format and works great but takes up size due to no compression. when it is saved to a png it is compressed using lossless compression algorithims. So if you are planning to perform in memory calculations. you have no choice but to use numpy but if you want bytes data then you will need to do manual slow conversions. (Note: The above is my opinion only) Commented May 27, 2021 at 12:55

1 Answer 1

2

You can get bytes by encoding as a png and then taking it as bytes. If you are storing many frames in memory this will help (as long as you can encode fast enough), but if the size of an individual frame is a problem, this may not be useful.

There is not a way I can find to return a non-numpy array from videocapture.

frameBytes = cv2.imencode('.png', frame)[1].tobytes() del frame # clear from memory 
Sign up to request clarification or add additional context in comments.

1 Comment

Hi ! Thanks for the idea ! Actually today I came across a library which does exactly what I need. imageZMQ - converts frames form cv video capture, compresses them and then sending over ZeroMQ messaging library.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.