# Yolo 11 python code for sources

**URL:** <https://community.ultralytics.com/t/yolo-11-python-code-for-sources/766>\
**Category:** YOLO\
**Tags:** code\
**Created:** [February 13, 2025, 6:34am UTC](https://community.ultralytics.com/t/yolo-11-python-code-for-sources/766 "2025-02-13T06:34:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cory\_B](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/cory_b/32/595_2.png) [@Cory\_B](https://community.ultralytics.com/u/Cory_B)\
**Post date:** [February 13, 2025, 6:34am UTC](https://community.ultralytics.com/t/yolo-11-python-code-for-sources/766/1 "2025-02-13T06:34:08Z")

</div>

I apparently haven’t been able to find some examples for all the different visual inputs and the code. I obviously understand that this very basic for all of you. I tried following a few youtube videos and have only gotten a photo and my webcam to work.

so how do you tell yolo to look at a:

photo - this worked but is it correct? results = model(“messy desk.jpg”)

video - I believe I’ve seen that it needs to be mp4 file type

webcam - this worked but is it correct? results = model.track(0, save=True, show=True,  
conf=0.2)

RTSP stream -

can you do a youtube video?

I apricate your time and sorry for the simple question. I’m trying to do this in Ubuntu in virtual environment using python.

---

<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:** [February 13, 2025, 7:07am UTC](https://community.ultralytics.com/t/yolo-11-python-code-for-sources/766/2 "2025-02-13T07:07:22Z")

</div>

The supported input formats are mentioned in the docs.

> **[Predict](https://docs.ultralytics.com/modes/predict/#inference-sources)**
>
> Harness the power of Ultralytics YOLO11 for real-time, high-speed inference on various data sources. Learn about predict mode, key features, and practical applications.

---

<div class="post-metadata">

**Author:** ![BurhanQ](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/burhanq/32/7_2.png) [@BurhanQ](https://community.ultralytics.com/u/BurhanQ)\
**Post date:** [February 14, 2025, 1:49pm UTC](https://community.ultralytics.com/t/yolo-11-python-code-for-sources/766/3 "2025-02-14T13:49:13Z")

</div>

FYI, just below the table on the page that Toxite linked to, you will find code examples for all inference sources. That’s the _best_ way to check for how to use “x” as a source.

> photo - this worked but is it correct? results = model(“messy desk.jpg”)

- Yes, but as the [Zen of Python](https://peps.python.org/pep-0020/) states, “Explicit is better than implicit.” so, it might be better to use:

> video - I believe I’ve seen that it needs to be mp4 file type

- All supported formats can be found on the Predict page of the docs that Toxite linked above, but if you want to jump directly to that section, [it’s here](https://docs.ultralytics.com/modes/predict/#image-and-video-formats).

> webcam - this worked but is it correct? results = model.track(0, save=True, show=True,  
> conf=0.2)

- Yes. Using `model.track(0)` or `model.predict(0)` will _generally_ access your webcam, however if there are multiple cameras connected, it could be a different number. See [this tutorial](https://docs.opencv.org/4.11.0/dd/d43/tutorial_py_video_display.html) and [related documentation](https://docs.opencv.org/4.x/d8/dfe/classcv_1_1VideoCapture.html#a57c0e81e83e60f36c83027dc2a188e80) from OpenCV (what’s used to access the [webcam stream](https://github.com/ultralytics/ultralytics/blob/d317b26940e4c064bd862cd5cfe426aaf76c41be/ultralytics/data/loaders.py#L122)).

> RTSP stream -

- Here it would be the same as any other URL or input object (again, definitely check out the documentation), however

```python
# NOTE: not a real RTSP URL
stream = model.predict(
    "rtsp://example.com/sample-rtsp-stream",
    stream=True, # must iterate to get results
)
results = []
for data in stream:
    results.append(data) # consumes resources quickly, not advised

```
