# When predicting, the Source parameter is multi-stream

**URL:** <https://community.ultralytics.com/t/when-predicting-the-source-parameter-is-multi-stream/489>\
**Category:** Support\
**Tags:** question, support\
**Created:** [November 9, 2024, 7:59am UTC](https://community.ultralytics.com/t/when-predicting-the-source-parameter-is-multi-stream/489 "2024-11-09T07:59:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Wei](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/eric_wei/32/320_2.png) [@Eric\_Wei](https://community.ultralytics.com/u/Eric_Wei)\
**Post date:** [November 9, 2024, 7:59am UTC](https://community.ultralytics.com/t/when-predicting-the-source-parameter-is-multi-stream/489/1 "2024-11-09T07:59:28Z")

</div>

When predicting, the Source parameter is multi-stream. How to obtain the corresponding stream unique identifier or other identifier from results?

---

<div class="post-metadata">

**Author:** ![pderrenger](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/pderrenger/32/73_2.png) [@pderrenger](https://community.ultralytics.com/u/pderrenger)\
**Post date:** [November 9, 2024, 8:27am UTC](https://community.ultralytics.com/t/when-predicting-the-source-parameter-is-multi-stream/489/2 "2024-11-09T08:27:48Z")

</div>

Hello!

Great question! When working with multi-stream sources in Ultralytics YOLO, you can manage and identify each stream by using a `.streams` text file. This file should contain one streaming URL per line, allowing you to run batched inference across multiple streams.

To obtain unique identifiers for each stream, you can modify your code to include a mapping between each stream URL and its corresponding identifier. Here’s a simple approach:

1. Create a dictionary that maps each stream URL to a unique identifier.
2. Use this dictionary to track results for each stream.

Here’s a quick example:

```python
from ultralytics import YOLO

# Load a pretrained YOLO model
model = YOLO("yolo11n.pt")

# Define your streams and identifiers
streams = {
    "rtsp://example.com/media1.mp4": "Stream1",
    "rtsp://example.com/media2.mp4": "Stream2",
    # Add more streams as needed
}

# Run inference on the streams
results = model(list(streams.keys()), stream=True)

# Process results and map them to identifiers
for result, stream_url in zip(results, streams.keys()):
    stream_id = streams[stream_url]
    print(f"Results for {stream_id}:")
    result.show() # Display results

```

This way, you can easily associate each result with its corresponding stream identifier. For more details on using multi-stream sources, check out the [Ultralytics YOLO documentation](https://docs.ultralytics.com/modes/predict/).

Feel free to ask if you have more questions! 😊

---

<div class="post-metadata">

**Author:** ![Eric\_Wei](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/eric_wei/32/320_2.png) [@Eric\_Wei](https://community.ultralytics.com/u/Eric_Wei)\
**Post date:** [November 9, 2024, 10:00am UTC](https://community.ultralytics.com/t/when-predicting-the-source-parameter-is-multi-stream/489/3 "2024-11-09T10:00:32Z")

</div>

Oh I see, so easy. Thank you very much

---

<div class="post-metadata">

**Author:** ![Eric\_Wei](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/eric_wei/32/320_2.png) [@Eric\_Wei](https://community.ultralytics.com/u/Eric_Wei)\
**Post date:** [November 10, 2024, 6:43am UTC](https://community.ultralytics.com/t/when-predicting-the-source-parameter-is-multi-stream/489/4 "2024-11-10T06:43:25Z")

</div>

Traceback (most recent call last):  
File “/data/workspace/Yolo/predict\_stream.py”, line 30, in   
for result, stream\_url in zip(results, streams.keys()):  
File “/home/aiusers/anaconda3/envs/pytorch\_2.0/lib/python3.9/site-packages/torch/utils/\_contextlib.py”, line 35, in generator\_context  
response = gen.send(None)  
File “/home/aiusers/anaconda3/envs/pytorch\_2.0/lib/python3.9/site-packages/ultralytics/engine/predictor.py”, line 226, in stream\_inference  
self.setup\_source(source if source is not None else self.args.source)  
File “/home/aiusers/anaconda3/envs/pytorch\_2.0/lib/python3.9/site-packages/ultralytics/engine/predictor.py”, line 198, in setup\_source  
self.dataset = load\_inference\_source(  
File “/home/aiusers/anaconda3/envs/pytorch\_2.0/lib/python3.9/site-packages/ultralytics/data/build.py”, line 187, in load\_inference\_source  
source, stream, screenshot, from\_img, in\_memory, tensor = check\_source(source)  
File “/home/aiusers/anaconda3/envs/pytorch\_2.0/lib/python3.9/site-packages/ultralytics/data/build.py”, line 162, in check\_source  
source = autocast\_list(source) # convert all list elements to PIL or np arrays  
File “/home/aiusers/anaconda3/envs/pytorch\_2.0/lib/python3.9/site-packages/ultralytics/data/loaders.py”, line 514, in autocast\_list  
files.append(Image.open(requests.get(im, stream=True).raw if str(im).startswith(“http”) else im))  
File “/home/aiusers/anaconda3/envs/pytorch\_2.0/lib/python3.9/site-packages/PIL/Image.py”, line 3247, in open  
fp = builtins.open(filename, “rb”)  
FileNotFoundError: [Errno 2] No such file or directory: ‘rtsp://xxx:xxx@1256@192.168.100.102:8554/test’

It determines that it is not a stream

---

<div class="post-metadata">

**Author:** ![Toxite](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/toxite/32/123_2.png) [@Toxite](https://community.ultralytics.com/u/Toxite)\
**Post date:** [November 10, 2024, 8:53am UTC](https://community.ultralytics.com/t/when-predicting-the-source-parameter-is-multi-stream/489/5 "2024-11-10T08:53:55Z")

</div>

The output results should be in the order of the streams. So the first stream would be in `results[0]`, second stream would be in `results[1]` and so on.

---

<div class="post-metadata">

**Author:** ![Eric\_Wei](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/eric_wei/32/320_2.png) [@Eric\_Wei](https://community.ultralytics.com/u/Eric_Wei)\
**Post date:** [November 10, 2024, 11:37am UTC](https://community.ultralytics.com/t/when-predicting-the-source-parameter-is-multi-stream/489/6 "2024-11-10T11:37:54Z")

</div>

I know how to deal with it. Save the variable streams to the .streams file.

This is because the method of load\_inference\_source and the method of check\_source failed to process list[str], str is stream url.

```auto
streams = {
    'rtsp://192.168.100.102:8554/test': 'channel_1001',
    'rtsp://192.168.100.103:8554/test': 'channel_1002',
}

with open('list.streams', 'w') as f:
    for url in streams.keys():
        f.write(url + '\n')
        
results = model('list.streams', stream=True, max_det=50, vid_stride=6, imgsz=640, device=3)

# Process results and map them to identifiers
for result, stream_url in zip(results, streams.keys()):
    stream_id = streams[stream_url]
    print(f"Results for {stream_id}:")

```
