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 the SkyLine instances is configured and the streaming pipeline was opened by calling start_streaming(), successive frames can be passed to the put() 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 the put() method with the frequency of the video_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 the LD_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).

video_width

The width of the frames in the video stream.

Type:

int

video_height

The height of the frames in the video stream.

Type:

int

video_fps

The number of frames per second sent to the video stream.

Type:

float

logger

The logger instance.

Type:

logging.Logger

class State(value)

Bases: Enum

States of the SkyLine.

STOPPED

The SkyLine instance is stopped.

START_WARMUP

The SkyLine instance is about to start the warmup period.

WARMUP

The SkyLine instance is measuring frame rate and frame size during the warmup period.

STREAMING

The SkyLine instance is streaming. The put() method should be called regularly.

ERROR

The SkyLine instance is encountered an error.

property state: State

State of the SkyLine.

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 same SkyLine 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 to None), 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, or USE_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, or USE_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, or USE_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 of numpy.uint8 type.

Returns:

True if the frame was effectively put on the downstream pipeline.

Return type:

bool

stop_streaming()

Stops the streaming.

Successive calls to put() method will silently discard the frames.

Return type:

None