skyline
SkyLine
streams OpenCV frames to a GStreamer pipeline.
SkyLine
itself is an abstract base class that you can not instantiate directly. Instead,
use one of the subclasses derived from SkyLine
that provide concrete implementation.
For example, KVSSkyLine
sends frames to AWS Kinesis Video Streams service,
and RTSPSkyLine
streams your frames with a built-in RTSP server.
- backpack.skyline.USE_LAST_VALUE = -999
Using this value for dynamic streaming attributes like fps, width and height will cause to use the values from the last streaming session.
- class backpack.skyline.SkyLine(parent_logger=None, gst_log_file=None, gst_log_level=None, dotenv_path=None)
Bases:
ABC
Abstract base class for sending OpenCV frames to a remote service using GStreamer.
SkyLine
can be used to create programmatically a video stream and send it to an external video ingestion service supported by GStreamer. Once theSkyLine
instances is configured and the streaming pipeline was opened by callingstart_streaming()
, successive frames can be passed to theput()
method of the instance in OpenCV image format (numpy.ndarray
with a shape of(height, width, 3)
, BGR channel order,numpy.uint8
type).The frequency of frames (frames per second) as well as the image dimensions (width, height) are static during the streaming. You can either specify these properties upfront in the constructor, or let SkyLine figure out these values. In the later case, up to
FPS_METER_WARMUP_FRAMES
frames (by default 100) will be discarded at the beginning of the streaming and during this period the value of the stream fps, width and height will be determined automatically. In all cases you are expected to call theput()
method with the frequency of thevideo_fps
property, and send images of (video_width
,video_height
) size.You should also specify
GST_PLUGIN_PATH
variable to the folder where the kvssink plugin binaries were built, and add the open-source dependency folder of kvssink to theLD_LIBRARY_PATH
variable. You can define these variables as environment variables, or in a file called.env
in the same folder where this file can be found.- Parameters:
parent_logger (Optional[Logger]) – If you want to connect the logger of KVS to a parent, specify it here.
gst_log_file (Optional[str]) – If you want to redirect GStreamer logs to a file, specify the full path of the file in this parameter.
gst_log_level (Optional[str]) – If you want to override GStreamer log level configuration, specify in this parameter.
dotenv_path (Optional[str]) – The path of the .env configuration file. If left to None, SkyLine will use the default search mechanism of the python-dotenv library to search for the .env file (searching in the current and parent folders).
- logger
The logger instance.
- Type:
- start_streaming(fps=-999, width=-999, height=-999)
Start the streaming.
After calling this method, you are expected to call the
put()
method at regular intervals. The streaming can be stopped and restarted arbitrary times on the sameSkyLine
instance.You should specify the desired frame rate and frame dimensions. Using
USE_LAST_VALUE
for any of theses attributes will use the value from the last streaming session. If no values are found (or the values are explicitly set toNone
), a warmup session will be started.- Parameters:
fps (float) – The declared frame per seconds of the video. Set this to
None
to determine this value automatically, orUSE_LAST_VALUE
to use the value from the last streaming session.width (int) – The declared width of the video. Set this to
None
to determine this value automatically, orUSE_LAST_VALUE
to use the value from the last streaming session.height (int) – The declared height of the video. Set this to
None
to determine this value automatically, orUSE_LAST_VALUE
to use the value from the last streaming session.
- Return type:
None
- put(frame)
Put a frame to the video stream.
- Parameters:
frame (numpy.ndarray) – A numpy array of
(height, width, 3)
shape and ofnumpy.uint8
type.- Returns:
True
if the frame was effectively put on the downstream pipeline.- Return type: