NvDsPyFuncPlugin
- class savant.deepstream.pyfunc.NvDsPyFuncPlugin(**kwargs)
DeepStream PyFunc plugin base class.
PyFunc implementations are defined in and instantiated by a
PyFunc
structure.- on_start()
Do on plugin start.
- on_event(event)
Add stream event callbacks.
- on_source_add(source_id)
On source add event callback.
- on_source_eos(source_id)
On source EOS event callback.
- on_source_delete(source_id)
On source delete event callback.
- get_cuda_stream(frame_meta)
Get a CUDA stream that can be used to asynchronously process a frame in a batch.
All frame CUDA streams will be waited for at the end of batch processing.
- process_buffer(buffer)
Process gstreamer buffer directly. Throws an exception if fatal error has occurred.
Default implementation calls
process_frame_meta()
andprocess_frame()
for each frame in a batch.- Parameters:
buffer (Buffer) – Gstreamer buffer.
- process_frame(buffer, frame_meta)
Process gstreamer buffer and frame metadata. Throws an exception if fatal error has occurred.
Use savant.deepstream.utils.get_nvds_buf_surface to get a frame image.
- Parameters:
buffer (Buffer) – Gstreamer buffer.
frame_meta (NvDsFrameMeta) – Frame metadata for a frame in a batch.
- get_runtime_metrics(n)
Get last runtime metrics.
- property metrics: MetricsRegistry
Get metrics registry.
Usage example:
from savant.metrics import Counter self.metrics['frames_per_source'] = Counter( name='frames_per_source', description='Number of processed frames per source', labelnames=('source_id',), ) ... self.metrics['frames_per_source'].inc(labels=('camera-1',))
- auxiliary_stream(source_id, width, height, codec_params, framerate='30/1')
Create an auxiliary stream.
Frames from auxiliary streams are encoded and sent to sink. They are not sent to downstream pipeline elements. This can be useful to send video in different resolutions, codecs, etc.
Usage example:
aux_stream = self.auxiliary_stream( source_id='aux-source', width=640, height=480, codec_params={'codec': 'h264'}, ) ... cuda_stream = self.get_cuda_stream(frame_meta) aux_frame, aux_buffer = aux_stream.create_frame(pts=pts) with nvds_to_gpu_mat(aux_buffer, batch_id=0) as aux_mat: cv2.cuda.resize( src=orig_frame_mat, dst=aux_mat, dsize=(640, 480), stream=cuda_stream, )