I'm using OpenCV to process some video data in a web service. Before calling OpenCV, the video is already loaded to a bytearray
buffer, which I would like to pass to VideoCapture
object:
# The following raises cv2.error because it can't convert '_io.BytesIO' to 'str' for 'filename'
cap = cv2.VideoCapture(buffer)
Unfortunately, VideoCapture()
expects a string filename, not a buffer. For now, I'm saving the bytearray
to a temporary file, and pass its name to VideoCapture()
.
Questions:
- Is there a way to create named in-memory files in Python, so I can pacify OpenCV?
- Alternatively, is there another OpenCV API which does support buffers?