pystreaming.stream package¶
Submodules¶
pystreaming.stream.handlers module¶
- pystreaming.stream.handlers.buffer(bufferlen, handlers)[source]¶
Buffer and reorder incoming packets of data.
- Parameters
bufferlen ([type]) – Length of buffer, in seconds.
handlers (dict) – Dictionary of str: generator. The key is a stream name, the value is an unprimed generator.
- Yields
tuple(str, data) – str is stream name, data is data packet from corresponding handler.
- pystreaming.stream.handlers.dispfps(handler, n=100, write=False)[source]¶
Average iterations per second over last n iterations.
- Parameters
handler (generator) – Generator that yields data.
n (int, optional) – Number of iterations to average over. Defaults to 100.
write (bool, optional) – Set to true to write FPS to data[‘arr’] instead of console, assuming it is a video frame. Defaults to False.
- Yields
pyobj – Forwards data from handler
- pystreaming.stream.handlers.display(frame, BGR=True)[source]¶
Display a frame using OpenCV.
Press [ESC] to stop.
- Parameters
frame (np.ndarray) – Frame must have dtype uint8.
BGR (bool, optional) – Is frame in BGR format (This is OpenCV format). Defaults to True.
- Raises
KeyboardInterrupt – Raised when [ESC] is pressed. Catch this exception to gracefully exit the stream.
pystreaming.stream.interface module¶
- pystreaming.stream.interface.recv(*, socket, arr=False, buf=False, flags=0)[source]¶
Internal video data receive command.
- Parameters
socket (zmq.Context.socket) – Socket through which to receive data.
arr (bool, optional) – Change to True if you expect an arr. Defaults to False.
buf (bool, optional) – Change to True if you expect a byte buffer. Defaults to False.
flags (int, optional) – Zmq flags to execute with (zmq.NOBLOCK). Defaults to 0.
- Returns
Expected items, with possible keys: {arr, buf, meta, ftime, fno}.
- Return type
dict
- pystreaming.stream.interface.send(*, socket, fno, ftime, meta, arr=None, buf=None, flags=0)[source]¶
Internal video data send command.
- Parameters
socket (zmq.Context.socket) – Socket through which to send data.
fno (int) – Frame number.
ftime (float) – Frame timestamp.
meta (pyobj) – Any reasonably small picklable object.
arr ([type], optional) – Numpy array to send. Defaults to None.
buf (bytes, optional) – Byte buffer to send. Defaults to None.
flags (int, optional) – Zmq flags to execute with (zmq.NOBLOCK or zmq.SNDMORE). Defaults to 0.
pystreaming.stream.patterns module¶
- class pystreaming.stream.patterns.Receiver(endpoint, nproc=2, mapreduce=False)[source]¶
Bases:
objectReceiver frames from a video stream.
- Parameters
endpoint (str) – Descriptor of collection endpoint.
nproc (int, optional) – Number of processes devoted to decoding. Defaults to 2.
mapreduce (bool, optional) – Enable Map-Reduce streaming pattern. Defaults to False.
- property handler¶
Returns a handler that is used for future data handling.
- Returns
Generator that yields dicts with keys {arr, meta, ftime, fno}.
- Return type
generator
- class pystreaming.stream.patterns.Streamer(endpoint, tracks=None, nproc=2, mapreduce=False)[source]¶
Bases:
objectVideo streamer with P2P and Map-Reduce functionality.
- Parameters
endpoint (str) – Descriptor of video stream endpoint.
tracks (list[str], optional) – Video stream tracks. Defaults to None which is [“none”].
nproc (int, optional) – Number of processes devoted to encoding. Defaults to 2.
mapreduce (bool, optional) – Enable Map-Reduce streaming pattern. Defaults to False.
- send(frame)[source]¶
Send a video frame into the stream.
- Parameters
frame (np.ndarray) – Video frame
- testcard(card, animated=False)[source]¶
Display a testcard or a test image. Automatically starts the device if not already started. This method is blocking.
- Parameters
card (int) – One of pystreaming.TEST_S pystreaming.TEST_M pystreaming.TEST_L pystreaming.IMAG_S pystreaming.IMAG_M pystreaming.IMAG_L
animated (bool, optional) – Set True to make image rotate. Defaults to False.
- class pystreaming.stream.patterns.Worker(source, drain, track='none', reqthread=3, decproc=2)[source]¶
Bases:
objectWorker in the Map-Reduce streaming pattern.
- Parameters
source (str) – Descriptor of Streamer.
drain (str) – Descriptor of Receiver.
track (str, optional) – Video stream track name. Defaults to “none”.
reqthread (int, optional) – Number of request threads. Defaults to 3.
decproc (int, optional) – Number of decoder processes. Defaults to 2.
- property handler¶
Returns a handler that is used for worker data handling.
- Returns
Generator that yields dicts with keys {arr, buf, meta, ftime, fno}.
- Return type
generator