videostream2py

stream2py interface to video.

Read frames from a video file or a camera device as a stream2py source.

The package’s entry point is VideoCapture, a stream2py.SourceReader backed by OpenCV’s cv2.VideoCapture:

>>> from videostream2py import VideoCapture
>>> VideoCapture.__name__
'VideoCapture'
>>> with VideoCapture(video_input=0) as cap:
...     timestamp, ret, frame = cap.read()

The re-export is lazy (PEP 562): a plain import videostream2py never imports OpenCV. Anything that actually materialises an exported name does – not only from videostream2py import VideoCapture but also import *, hasattr, inspect.getmembers() and help(). So on a host where import cv2 itself fails – Linux without libGL.so.1 – importing this package still works, while introspecting it raises that ImportError.

class videostream2py.VideoCapture(video_input: str | int = 0)[source]

Video Capture using OpenCV

close() None[source]

Close and clean up source reader. Will be called when StreamBuffer stops or if an exception is raised during read and append loop.

property info: dict

A dict with important source info. Default can be init_kwargs and open timestamp.

This info will be available in BufferReader after SourceReader has opened but any changes made between open and close are not guaranteed to be visible. Any continuous status updates should be included with read data instead.

Returns:

dict

key(data) ComparableType[source]
Parameters:

data – (timestamp, ret, frame)

Returns:

timestamp

open() None[source]

Set up source to be read and set some source info affected by open time like the time of open. Will be called in StreamBuffer immediately before first read.

classmethod video_input_info(video_input: str | int) dict[source]

https://docs.opencv.org/4.2.0/d4/d15/group__videoio__flags__base.html#gaeb8dd9c89c10a5c63c139bf7c4f5704d

Parameters:

video_input – filename or device id, see cv2.VideoCapture documentation for more info

Returns:

dict