# Stream Reader

This function block plays network streams (YouTube, Twitch, HTTP/RTSP and similar) in the background and keeps the latest frame ready for other blocks to consume. It is designed for continuous stream previewing and downstream processing with controls for playback rate, requested quality and frame rate limiting.

## 📥 Inputs <a href="#inputs" id="inputs"></a>

This function block does not have any inputs.

## 📤 Outputs <a href="#outputs" id="outputs"></a>

`Image Any` The latest frame retrieved from the provided streaming source (keeps updating as the stream plays).

## 🕹️ Controls <a href="#controls" id="controls"></a>

`Status` Displays current state and helpful messages (e.g., waiting, connecting, live, paused, reconnecting).

`Stream URL` Enter the stream address or link you want to play (examples: public live links, HTTP livestreams, or provider links).

`Playback speed` Adjust playback rate (range shown in the UI). Use values below 1.0 for slow motion or above 1.0 for faster playback.

`Preferred quality` Request a preferred stream quality when multiple renditions are available (e.g., Best, 1080p, 720p).

`FPS limit` Limit the outgoing frame rate produced by this block. Set to 0 to use the source's native frame rate.

`Pause playback` Toggle to pause/resume the stream without closing the connection.

## 🎨 Features <a href="#features" id="features"></a>

* Background streaming: plays remote streams on a background process so the UI remains responsive while keeping the latest frame available.
* Robust connection handling: shows clear status messages (connecting, live, paused, reconnecting) and attempts to recover from transient errors.
* Playback control: control playback speed and request a specific rendition when available.
* Frame rate limiting: reduce downstream load by capping frames per second.
* Optional remote frame upload: when configured, captured frames can be sent to a remote uploader for storage or logging.
* Pause without losing last frame: pausing keeps the last frame available for inspection or processing.

## 📝 Usage Instructions <a href="#usage" id="usage"></a>

1. Enter a streaming link into `Stream URL`.
2. Adjust `Preferred quality` if you want a specific rendition.
3. Set desired `Playback speed` and `FPS limit` to control how the stream is delivered to downstream blocks.
4. Use `Pause playback` to temporarily halt frame updates while keeping the connection.
5. Connect this block's output `Image Any` to visualization or processing blocks to consume live frames.

## 📊 Evaluation <a href="#evaluation" id="evaluation"></a>

When active, this function block continuously fetches frames from the configured stream and provides the most recent frame through the `Image Any` output. Status messages update to reflect connection state. If paused, frame updates stop but the last frame remains available.

## 💡 Tips and Tricks <a href="#tips-and-tricks" id="tips-and-tricks"></a>

* To preview the live stream interactively, connect the `Image Any` output to the `Show Image` block so you can open the image viewer and inspect frames.
* Reduce CPU/GPU load by connecting `Image Any` to an `Image Resizer` block before heavy AI blocks like `Object Detection (D-FINE)`, `Mask Detection`, `Pose Estimation`.
* For long-term recording or debugging, pipe the output to `Record Video`, `Image Logger` or `Image Write`.
* Use `Background Subtractor` on the stream output to detect motion or extract foreground regions for downstream detectors (e.g., `Object Detection - Custom`).
* If you need to focus on a specific area of the scene, use `Image ROI`, `Image ROI Select` or `Image ROI Polygon` before detection or measurement blocks (like `Find Object` or `Histogram On Line`).
* Combine with `Object_Detection_Tracker` and `Draw Detections` to track and visualize detected objects across frames from the stream.
* For OCR on live streams, connect the output to `OCR` or `OCR (EasyOCR)` after applying suitable cropping (`Image ROI Select`) and image enhancement (`Contrast Optimization` or `Denoising`).
* If the stream source is large or unstable, try lowering `FPS limit` or reducing `Preferred quality` to improve stability and reduce bandwidth.

## 🛠️ Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

* If the status shows "Waiting for stream link", ensure `Stream URL` is a full URL including the scheme (e.g., `http://`, `https://`, `rtsp://`).
* If connection fails or frequently reconnects, try lowering requested quality or reducing the FPS limit to ease bandwidth and processing.
* If frames stop updating while status shows live, toggle `Pause playback` off and on to force a refresh.
* If you need to debug connection messages, monitor the block's `Status` label for textual hints about connection progress or errors.


---

# 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://docs.augelab.com/function-blocks/input-output/image-inputs/stream-reader.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.
