Starting a Stream

To start a stream through the SDK, use the steps below :

1

Create a Stream Object

ms = Stream("your-index-name")
2

Discover Available Sources

sources = ms.sources()  # returns a list of device names
print(sources)

Example console output would look like the following:

2 Sources Detected
==================================================
Device Camera or Screen
--------------------------------------------------
0 FaceTime HD Camera
1 Color LCD (1728 x 1117 @ 120 Hz)
==================================================
3

Select a Source

ms.set(1)  # choose the “Color LCD” screen capture from the list above

If no source is set explicitly, index 0 is used by default.

4

Start Streaming

ms.start()  # stream indefinitely (Ctrl-C to stop)

# OR limit the session to N seconds
ms.start(30)  # stream for 30 seconds

Once started, the stream will begin capturing video from the selected source functions can be run on the stream from its respective index. For example:

resp = moonshine.search(
    index="your-index-name",
    query="some prompt here"
)

Best Practices

Some best practices for streaming:

  1. Verify devices first with ms.sources()— ID ordering can change between reboots.
  2. Combine live Stream sessions with batch upload() to cover both real-time and historical footage.
  3. Keep streams short when testing (ms.start(10)) to conserve local and network resources.
  4. Use search or inquire during a live session to build interactive dashboards or alerts.


Stream() methods