cyndilib.receiver#

Receiver#

class cyndilib.receiver.Receiver#

Bases: object

A receiver for NDI® streams

Parameters:
  • source_name (str, optional) – The NDI® source name to connect to. An empty string (default) indicates no source

  • source (Source, optional) – A Source object to connect to. None (default) indices no source.

  • color_format – The RecvColorFormat to accept

  • bandwidth – The RecvBandwidth to use

  • allow_video_fieldsTrue if interlaced video frames can be handled. If False, only progressive frames will be delivered.

  • recv_name – Name for the receiver

source_name#

The current NDI® source name

Type:

str

source#

The current Source object

Type:

Source

video_frame#
Type:

VideoRecvFrame

audio_frame#
Type:

AudioRecvFrame

metadata_frame#
Type:

MetadataRecvFrame

frame_sync#
Type:

FrameSync

ptz#

Access to the PTZ methods.

Type:

PTZ

connect_to(self, src: Source)#

Alias for set_source()

disconnect(self)#

Disconnect from the source (if connected)

get_num_connections(self)#
get_performance_data(self)#
is_connected(self)#

Returns True if currently connected

is_ptz_supported(self)#

Returns True if the source accepts PTZ commands

New in version 0.0.7.

preview_tally#

Indicates the preview tally state as set by set_source_tally_program()

program_tally#

Indicates the program tally state as set by set_source_tally_program()

receive(self, recv_type: ReceiveFrameType, timeout_ms: int) ReceiveFrameType#

Receive frame data of the given type

If requesting a video or audio frame and the result indicates data was received, the incoming frame data will be available in the video_frame or audio_frame.

Parameters:
  • recv_type (ReceiveFrameType) – The frame type(s) to receive

  • timeout_ms (int) – Time (in milliseconds) to wait for a frame to be available

Returns a ReceiveFrameType indicating what was received. If nothing was available before the timeout, the result will be ReceiveFrameType.nothing

reconnect(self)#
set_audio_frame(self, af: AudioRecvFrame)#

Set the audio_frame

set_metadata_frame(self, mf: MetadataRecvFrame)#

Set the metadata_frame

set_source(self, src: Source)#

Set the current source

If the source is None, disconnects if necessary. Otherwise, attempt to connect to it.

set_source_tally_preview(self, value: bool)#

Set the preview tally state for the currently connected source

See notes in the set_source_tally_program() method

set_source_tally_program(self, value: bool)#

Set the program tally state for the currently connected source.

This method sends a tally command to the source and does not necessarily affect the state of the source object’s tally. It will be updated independently when tally metadata is received.

This is because other receivers may have also sent tally messages to the source. When this occurs, the source’s tally remains “on” until all of its connected receivers have set it to “off” (like a bitwise “OR”)

set_video_frame(self, vf: VideoRecvFrame)#

Set the video_frame

PTZ#

class cyndilib.receiver.PTZ#

Bases: object

PTZ control for a Receiver

autofocus(self)#

Re-enables / triggers the autofocus.

New in version 0.0.7.

exposure_auto(self)#

(Re-)enables the auto exposure mode.

New in version 0.0.7.

focus(self, focus_speed: float)#

Controls the focus of the camera.

The assumption is that this function is called continuously, for example while pressing a button in a GUI or HID.

>>> for _ in range(0, 100):
...     time.sleep(0.05)
...     receiver.ptz.focus(.5)
Parameters:

focus_speed (float) – -1.0 (focus out) … 0.0 (no change) … 1.0 (focus in)

New in version 0.0.7.

pan(self, pan_speed: float)#

Pan the camera.

The assumption is that this function is called continuously, for example while pressing a button in a GUI or HID.

>>> for _ in range(0, 100):
...     time.sleep(0.05)
...     receiver.ptz.pan(.5)
Parameters:

pan_speed (float) – 1.0 (fastest left) … 0.0 (no movement) … -1.0 (fastest right)

This is the same as pan_and_tilt(pan_speed, 0.0), see pan_and_tilt().

New in version 0.0.7.

pan_and_tilt(self, pan_speed: float, tilt_speed: float)#

Pan and tilt the camera.

The assumption is that this function is called continuously, for example while pressing a button in a GUI or HID.

>>> for _ in range(0, 100):
...     time.sleep(0.05)
...     receiver.ptz.pan_and_tilt(.5)
Parameters:
  • pan_speed (float) – 1.0 (fastest left) … 0.0 (no movement) … -1.0 (fastest right)

  • tilt_speed (float) – -1.0 (fastest downwards) … 0.0 (no movement) … 1.0 (fastest upwards)

Attention

1 is to the left, and -1 is to the right!

New in version 0.0.7.

recall_preset(self, preset_no: int, speed: float)#

Recalls a previously stored PTZ preset.

This includes position, focus, …. The speed indicates how fast the camera moves to the position.

Parameters:
  • preset_no (int) – 099

  • speed (float) – 0.0 (slowest) … 1.0 (fastest)

New in version 0.0.7.

set_exposure_coarse(self, exposure_level: float)#

Manually control the exposure.

See also set_exposure_fine().

Parameters:

exposure_level (float) – 0.0 (dark) … 1.0 (bright)

Note

Use either this or set_exposure_fine(). There’s no value in using both. Prefer set_exposure_fine().

New in version 0.0.7.

set_exposure_fine(self, iris: float, gain: float, shutter_speed: float)#

Precisely control the exposure.

See also set_exposure_coarse().

Parameters:
  • iris (float) – 0.0 (closed) … 1.0 (open)

  • gain (float) – 0.0 (low) … 1.0 (high)

  • shutter_speed (float) – 0.0 (slow) … 1.0 (fast)

Note

Use either this or set_exposure_coarse(). There’s no value in using both. Prefer this method.

New in version 0.0.7.

set_focus(self, focus_value: float)#

Sets focus to a specific value.

Parameters:

focus_value (float) – 0.0 (max focus out; infinity) … 1.0 (max focus in)

New in version 0.0.7.

set_pan_and_tilt_values(self, pan_value: float, tilt_value: float)#

Set pan and tilt angles of the camera.

Parameters:
  • pan_value (float) – -1.0 (leftmost) … 0.0 (center) … 1.0 (right)

  • tilt_value (float) – -1.0 (bottom) … 0.0 (middle) … 1.0 (top)

Note

Some cameras (e.g. OBSBOT) only support tilt values from -0.5 to 0.5.

New in version 0.0.7.

set_white_balance(self, red: float, blue: float)#

Manually set the white balance values.

Parameters:
  • red (float) – 0.0 … 1.0

  • blue (float) – 0.0 … 1.0

New in version 0.0.7.

set_zoom_level(self, zoom_level: float)#

Set the PTZ zoom level

Parameters:

zoom_level (float) – 0.0 (max zoomed out) … 1.0 (max zoomed in)

New in version 0.0.7.

store_preset(self, preset_no: int)#

Store the current PTZ configuration as preset.

This includes position, focus, ….

Parameters:

preset_no (int) – 099

New in version 0.0.7.

tilt(self, tilt_speed: float)#

Pan and tilt the camera.

The assumption is that this function is called continuously, for example while pressing a button in a GUI or HID.

>>> for _ in range(0, 100):
...     time.sleep(0.05)
...     receiver.ptz.tilt(.5)
Parameters:

tilt_speed (float) – -1.0 (fastest downwards) … 0.0 (no movement) … 1.0 (fastest upwards)

This is the same as pan_and_tilt(0.0, tilt_speed), see pan_and_tilt().

New in version 0.0.7.

white_balance_auto(self)#

Changes the white balance to auto mode.

New in version 0.0.7.

white_balance_indoor(self)#

Changes the white balance to indoor mode.

New in version 0.0.7.

white_balance_oneshot(self)#

Determines the white balance automatically from the center of the current frame.

New in version 0.0.7.

white_balance_outdoor(self)#

Changes the white balance to outdoor mode.

New in version 0.0.7.

zoom(self, zoom_speed: float)#

Zoom the camera with the given speed.

The assumption is that this function is called continuously, for example while pressing a button in a GUI or HID.

>>> for _ in range(0, 100):
...     time.sleep(0.05)
...     receiver.ptz.zoom(.5)
Parameters:

zoom_speed (float) – -1.0 (zoom out, max speed) … 0.0 (no zooming) … 1.0 (zoom in, max speed)

New in version 0.0.7.

RecvThread#

class cyndilib.receiver.RecvThread(receiver, timeout_ms, recv_frame_type=7, wait_time=0.1)#

Bases: Thread

A thread designed for use with Receiver

Repeatedly calls Receiver.receive() using the supplied arguments. A callback is then triggered whenever new frames are received.

This can be used to handle video and audio using two separate threads. One thread would be set to use recv_video and the other to recv_audio.

Parameters:
run(self)#
set_callback(self, cb)#

Set the callback used to indicate new frames

set_wait_event(self)#
stop(self)#

Stop the thread

ReceiveFrameType#

class cyndilib.receiver.ReceiveFrameType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)#

Bases: IntFlag

Frame type flags used to receive specific frame types and indicate results. Members and be combined using bit-wise operators.

nothing#

Indicate nothing can or has been received

recv_video#

Indicate video frames can or have been received

recv_audio#

Indicate video frames can or have been received

recv_metadata#

Indicate metadata frames can or have been received

recv_status_change#

Indicate a status change has occurred (results only)

recv_error#

Indicate an error occurred (results only)

recv_buffers_full#

Indicates a VideoRecvFrame or AudioRecvFrame buffer was full when trying to read (results only)

recv_all#

A combination of recv_video, recv_audio and recv_metadata