savant_rs.pipeline

class savant_rs.pipeline.FrameProcessingStatRecord
frame_no
id
object_counter
record_type
stage_stats
ts
class savant_rs.pipeline.FrameProcessingStatRecordType
Frame = FrameProcessingStatRecordType.Frame
Initial = FrameProcessingStatRecordType.Initial
Timestamp = FrameProcessingStatRecordType.Timestamp
class savant_rs.pipeline.StageFunction
static none()
class savant_rs.pipeline.StageStat
batch_counter
frame_counter
object_counter
queue_length
stage_name
class savant_rs.pipeline.VideoPipeline(name, stages, configuration)

A video pipeline.

access_objects(frame_id, query, no_gil=True)
add_batched_frame_update(batch_id, frame_id, update)

Adds a frame update to the batched frame.

GIL management: the function is GIL-free.

Parameters:
Raises:

ValueError – If the stage does not exist or is not of type batches. If the batch or the frame do not exist.

add_frame(stage_name, frame)

Adds a frame to the stage.

GIL management: the function is GIL-free.

Parameters:
  • stage_name (str) – The name of the stage. Must be a stage of type independent frames.

  • frame (savant_rs.primitives.VideoFrameProxy) – The frame to add.

Returns:

The id of the frame.

Return type:

int

Raises:

ValueError – If the stage does not exist or is not of type independent frames.

add_frame_update(frame_id, update)

Adds a frame update to the independent frame.

Parameters:
Raises:

ValueError – If the stage does not exist or is not of type independent frames. If the frame does not exist.

add_frame_with_telemetry(stage_name, frame, parent_span)

Adds a frame to the stage with an OTLP parent context.

GIL management: the function is GIL-free.

Parameters:
  • stage_name (str) – The name of the stage. Must be a stage of type independent frames.

  • frame (savant_rs.primitives.VideoFrameProxy) – The frame to add.

  • parent_ctx (savant_rs.utils.TelemetrySpan) – The parent context to add to the frame.

Returns:

The id of the frame.

Return type:

int

Raises:

ValueError – If the stage does not exist or is not of type independent frames.

apply_updates(id, no_gil=True)

Applies the updates to the frames and batches of a stage.

GIL management: the function is GIL-free.

Parameters:

id (int) – The id of the frame or batch to apply updates for.

Raises:

ValueError – If the stage does not exist. If the frame or batch does not exist.

clear_source_ordering(source_id)

Clears the ordering for source, called on dead stream eviction.

Parameters:

source_id (str) – The id of the source.

Raises:

ValueError – If the source does not exist.

clear_updates(id)

Clears the updates to the frames and batches of a stage.

GIL management: the function is GIL-free.

Parameters:

id (int) – The id of the frame or batch to clear updates for.

Raises:

ValueError – If the stage does not exist. If the frame or batch does not exist.

delete(id)

Deletes a frame or a batch from the stage.

GIL management: the function is GIL-free.

Parameters:

id (int) – The id of the frame or batch to delete.

Returns:

The ids of the frames and their telemetry contexts.

Return type:

dict[int, savant_rs.utils.TelemetrySpan]

Raises:

ValueError – If the stage does not exist. If the frame or batch does not exist.

get_batch(batch_id)

Retrieves a batch from a specified stage.

GIL management: the function is GIL-free.

Parameters:

batch_id (int) – The id of the batch.

Returns:

The batch and propagation contexts for every frame.

Return type:

(savant_rs.primitives.VideoFrameBatch, Dict[int, savant_rs.utils.TelemetrySpan])

Raises:

ValueError – If the stage does not exist or is not of type batches. If the batch does not exist.

get_batched_frame(batch_id, frame_id)

Retrieves a batched frame from a specified stage.

GIL management: the function is GIL-free.

Parameters:
  • batch_id (int) – The id of the batch.

  • frame_id (int) – The id of the frame.

Returns:

The frame and the OTLP propagation context corresponding to the current phase of processing.

Return type:

(savant_rs.primitives.VideoFrameProxy, savant_rs.utils.TelemetrySpan)

Raises:

ValueError – If the stage does not exist or is not of type batches. If the batch or the frame do not exist.

get_independent_frame(frame_id)

Retrieves an independent frame from a specified stage.

GIL management: the function is GIL-free.

Parameters:

frame_id (int) – The id of the frame.

Returns:

The frame.

Return type:

(savant_rs.primitives.VideoFrameProxy, savant_rs.utils.TelemetrySpan)

Raises:

ValueError – If the stage does not exist or is not of type independent frames. If the frame does not exist.

get_keyframe_history(f)
get_stage_queue_len(stage_name)

Retrieves the length of the queue of a stage.

GIL management: the function is GIL-free.

Parameters:

stage_name (str) – The name of the stage.

Returns:

The length of the queue of the stage.

Return type:

int

Raises:

ValueError – If the stage does not exist.

get_stage_type(name)

Retrieves the type of a stage.

Parameters:

name (str) – The name of the stage.

Returns:

The type of the stage. Either independent frames or batches.

Return type:

VideoPipelineStagePayloadType

Raises:

ValueError – If the stage does not exist.

get_stat_records(max_n)
get_stat_records_newer_than(id)
log_final_fps()
memory_handle

Allows receiving a raw pointer to Rust inner Pipeline struct.

move_and_pack_frames(dest_stage_name, frame_ids, no_gil=True)

Moves frames from the stage with independent frames to the stage with batches.

GIL management: the function is GIL-free.

Parameters:
  • dest_stage_name (str) – The name of the destination stage.

  • frame_ids (List[int]) – The ids of the frames to move.

Returns:

The id of the batch.

Return type:

int

Raises:

ValueError – If the source stage does not exist or destination stage does not exist. If the source stage is not of type independent frames or the destination stage is not of type batches. If the frame does not exist.

move_and_unpack_batch(dest_stage_name, batch_id, no_gil=True)

Moves a batch from the stage with batches to the stage with independent frames.

GIL management: the function is GIL-free.

Parameters:
  • dest_stage_name (str) – The name of the destination stage.

  • batch_id (int) – The id of the batch to move.

Returns:

The map of stream_id: id for the frames unpacked from the batch.

Return type:

Dict[str, int]

Raises:

ValueError – If the source stage does not exist or destination stage does not exist. If the source stage is not of type batches or the destination stage is not of type independent frames. If the batch does not exist.

move_as_is(dest_stage_name, object_ids, no_gil=True)

Moves frames or batches from a stage to another. The dest stage must be the same time as the source stage.

GIL management: the function is GIL-free.

Parameters:
  • dest_stage_name (str) – The name of the destination stage.

  • object_ids (List[int]) – The ids of the frames or batches to move.

Raises:

ValueError – If the source stage does not exist. If the destination stage does not exist. If the source stage and the destination stage are not of the same type. If the frame or batch does not exist.

root_span_name

Returns the root span name.

sampling_period

Set sampling. Sampling is used to reduce the number of spans sent to an OTLP collector. By default, it is set to 0, which means that spans are only produced for propagated telemetry.

Params

periodint

The sampling period. If set to 0, no sampling is performed. Set it to a high number (e.g. 100, 1000) for production, 1 for development purposes to trace every frame.

class savant_rs.pipeline.VideoPipelineConfiguration
append_frame_meta_to_otlp_span
collection_history
frame_period
keyframe_history
timestamp_period
class savant_rs.pipeline.VideoPipelineStagePayloadType

Defines which type of payload a stage handles.

Batch = VideoPipelineStagePayloadType.Batch
Frame = VideoPipelineStagePayloadType.Frame
savant_rs.pipeline.load_stage_function_plugin(libname, init_name, plugin_name, params)