# Stream Assets

In this section you can find Misty's APIs for streaming content to and from Misty.

### **StartVideoStreaming**

Starts Misty video streaming.

To use the websocket, you can connect to it from a browser using:ws\://\<robot-ip-address>:\<port>

Video streaming consumes extra resources, so when you are done using the stream, you should call the `StopVideoStreaming` command.

**Example Code**

{% hint style="success" %}

```python
misty.start_video_streaming(5678,0,0,0,100,"false")
```

{% endhint %}

**Parameters**

{% code overflow="wrap" %}

```python
misty.start_video_streaming(self, port : int = None, rotation : int = None, width : int = None, height : int = None, quality : int = None, overlay : bool = None) -> Response:
```

{% endcode %}

* Port (int) - Optional. The websocket port. Must be between 1024 and 65535, default is 5678.
* Rotation (int) - Optional. Stream rotation. Must be between 0 and 180, default is 0.
* Width (int) - Optional. Must be between 200 and 1600. Default is 0 and does not adjust the image.
* Height (int) - Optional. Must be between 200 and 1600. Default is 0 and does not adjust the image.
* Quality (int) - Optional. Image quality, which can affect performance. Must be between 1 and 100. Default is 100.
* Overlay (bool) - Optional. Whether to add overlay information, like face tracking, to the stream. Default is false.

### **StopVideoStreaming**

Stops Misty video streaming.

{% hint style="success" %}

```python
misty.stop_video_streaming
```

{% endhint %}

### **StartAVStreaming**

Starts Misty streaming audio and video from her microphones and RGB camera to an external source.

**Important!** Misty's AV stream is **NOT** encrypted at this time. Devices on the same network as your robot (or in between your robot and the streaming server or client) can intercept the stream, play back the content, and re-publish the stream outside of your local network. Additionally, you are responsible for securing and encrypting any media content you choose to stream from Misty to services or devices outside of your local network.

Valid resolutions (as `width` x `height`) for AV streaming are: 1920 x 1280, 1280 x 960, 640 x 480, and 320 x 240.

* By default, Misty's AV streaming service is disabled when the robot boots up. You must enable this service before you can start AV streaming. You can enable the AV streaming service with the `EnableAvStreamingService` command.
* Enabling the AV streaming service automatically disables Misty's camera service. Misty cannot take pictures, record videos, or use computer vision functionality (such as face detection or face recognition) while the AV streaming service is enabled. For more information, see AV Streaming Service.
* Misty cannot use her microphones for wake word detection, recording audio, or capturing speech while actively streaming audio and video.
* Misty's AV streaming service is unidirectional at this time. You can stream audio and video from Misty to an external device, but the robot cannot play live media streams.
* Misty's video stream is rotated 90 degrees counterclockwise. You can rotate the stream to the orientation you prefer by changing the settings in your streaming client.
* This command is currently in **Beta**, and related hardware, firmware, or software is still under development. Feel free to use this command, but recognize that it may behave unpredictably at this time.

Misty supports the following modes for AV streaming:

* Misty can transmit a live audio and video data stream to an external media server that you configure to run on the same network as the robot. Misty supports streaming over Real-Time Messaging Protocol (RTMP) or Real Time Streaming Protocol (RTSP). You must create and host the media server yourself and configure the server to publish a stream you can view with a streaming client (like [VLC](https://www.videolan.org/vlc/)).
* Misty can serve an RTSP stream herself, and you can view the stream with a client connected to the same network as the robot. Misty's server can stream to clients that use TCP or UDP to receive AV streaming data.

**Note**: For lowest latency use RTSP instead of RTMP. To decrease latency further, adjust the network caching settings for your streaming client.

**Example Code**

{% hint style="success" %}

```python
// This example sets Misty up to act as her own media server. Connect
// to this stream from a client on the same network as Misty. The URL
// for this stream would be: rtsp://<robot-ip-address>:1936

misty.start_av_streaming("rtspd:1936", 640, 480)
```

{% endhint %}

**Parameters**

{% code overflow="wrap" %}

```python
misty.start_av_streaming(self, url : str = None, width : int = None, height : int = None, frameRate : int = None, videoBitRate : int = None, audioBitRate : int = None, audioSampleRateHz : int = None, userName : str = None, password : str = None)
```

{% endcode %}

* URL (string) - **Option 1**: If transmitting a stream from Misty to an external media server, this value is the URL address for the streaming server. This value **must** match the URL used when you set up the streaming server. You must prefix the URL with either `rtmp://` or `rtsp://`, depending on the streaming protocol you want to use. **Option 2:** To use Misty as her own media server, use `rtspd:<port-number>`, where `<port-number>` is the port through which to publish the stream (for example, `rtspd:1935`). When the stream is live, you can view it in your media client by connecting to `rtsp://<robot-ip-address>:<port-number>` (for example, `rtsp://192.168.7.30:1935`).
* Width (int) - Optional. The width (in pixels) of the video stream. The default resolution for video streaming (as `width` x `height`) is 1920 x 1080.
* Height (int) - Optional. The height (in pixels) of the video stream. The default resolution for video streaming (as `width` x `height`) is 1920 x 1080.
* FrameRate (int) - Optional. The frame rate at which Misty streams video. You must use a value greater than `1` and less than `30`. Default is `30`.
* VideoBitRate (int) - Optional. The bitrate (in bits per second) at which to encode streamed video data. Defaults to `5000000` (5 mbps). Valid values are between `256000` (256 kbps) and `20000000` (20 mbps).
* AudioBitRate (int) - Optional. The bitrate (in bits per second) at which to encode streamed audio data. Defaults to `128000` (128 kbps). Valid values are between `32000` (32 kbps) and `1000000` (1 mbps).
* AudioSampleRateHz (int) - Optional. The sample rate (in hz) at which to record audio for the audio stream. Defaults to `44100` (44.1 kHz). Supported sample rates include: `11025`, `12000`, `16000`, `22050`, `24000`, `32000`, `44100`, and `48000`.
* UserName (string) - Optional. The username a stream must supply to transmit media to your external server. Not all servers require a username and password. You can change whether to require credentials when you set up your server.
* Password (string) - Optional. The password for connecting to your external media server.

### StopAVStreaming

Stops Misty streaming audio and video.

{% hint style="success" %}

```
misty.stop_av_streaming
```

{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lessons.mistyrobotics.com/python-elements/misty-python-api/stream-assets.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
