Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yolov5 Youtube playback error #13111

Open
2 tasks done
hsinpaul opened this issue Jun 20, 2024 · 4 comments
Open
2 tasks done

yolov5 Youtube playback error #13111

hsinpaul opened this issue Jun 20, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@hsinpaul
Copy link

hsinpaul commented Jun 20, 2024

Search before asking

  • I have searched the YOLOv5 issues and found no similar bug report.

YOLOv5 Component

Detection

Bug

(yolov5) E:\yolov5>detect.py --source https://youtu.be/qNEggYgsY0M?si=8ZOJr7HTNPcKx--F
detect: weights=yolov5s.pt, source=https://youtu.be/qNEggYgsY0M?si=8ZOJr7HTNPcKx--F, data=data\coco128.yaml, imgsz=[640, 640], conf_thres=0.25, iou_thres=0.45, max_det=1000, device=, view_img=False, save_txt=False, save_csv=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=runs\detect, name=exp, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False, dnn=False, vid_stride=1
YOLOv5 v7.0-326-gec331cbd Python-3.12.4 torch-2.3.1+cpu CPU

Fusing layers...
YOLOv5s summary: 213 layers, 7225885 parameters, 0 gradients, 16.4 GFLOPs
[ WARN:[email protected]] global cap.cpp:166 cv::VideoCapture::open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.10.0) D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap_images.cpp:244: error: (-5:Bad argument) CAP_IMAGES: error, expected '0?[1-9][du]' pattern, got: https://rr1---sn-ipoxu-un5e7.googlevideo.com/videoplayback?expire=1718870464&ei=YI1zZqrwMuzN2roPpcKr0A0&ip=2001%3Ab400%3Ae2d6%3A1675%3A3171%3A94f7%3A16d8%3A97ef&id=o-AJcMhuCchrU4niZjIUv6Gd8nk1avhQ1DlobLgVSmp80L&itag=18&source=youtube&requiressl=yes&xpc=EgVo2aDSNQ%3D%3D&mh=Zv&mm=31%2C26&mn=sn-ipoxu-un5e7%2Csn-ogul7nel&ms=au%2Conr&mv=m&mvi=1&pl=44&initcwndbps=982500&bui=AbKP-1MSYNWPqI6IaDHZoFajm7h7URFhgVTS80lZHe1nUoZjaQcZR0u9RIRidzaljFcBRYXIRyjk8Jho&spc=UWF9fy_IjYkzdE33U2Y1J9AXNGQ4uWDswT31WqaL-pTxF3_TpAzwxYPRIH2N&vprv=1&svpuc=1&mime=video%2Fmp4&ns=n-unt47rEMcb59I5p4YGJHQQ&rqh=1&cnr=14&ratebypass=yes&dur=601.420&lmt=1715885202750992&mt=1718848382&fvip=3&c=WEB&sefc=1&txp=6218224&n=niZkvTCch8pWhIMVBf&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cxpc%2Cbui%2Cspc%2Cvprv%2Csvpuc%2Cmime%2Cns%2Crqh%2Ccnr%2Cratebypass%2Cdur%2Clmt&sig=AJfQdSswRAIgZ8_wSb5aeRDIhlIqUHy_dQfzDFM9-lIO4Jg0HnrhrdkCIBHRsWIqtauEykKlxVErxCSBRmH4RKquHNzzLiOypm4b&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHlkHjAwRgIhAMhHdJSJahwI2N5UkNRnVbzvXIoDr-Ha7RzZSI0QzISEAiEApWosq3KAFcpUuEbUzPdqNb_AImQ9qp8aPaC350-j3xU%3D in function 'cv::icvExtractPattern'

Traceback (most recent call last):
File "E:\yolov5\detect.py", line 312, in
main(opt)
File "E:\yolov5\detect.py", line 307, in main
run(**vars(opt))
File "C:\Users\pega_user\AppData\Local\Programs\Python\Python312\Lib\site-packages\torch\utils_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "E:\yolov5\detect.py", line 123, in run
dataset = LoadStreams(source, img_size=imgsz, stride=stride, auto=pt, vid_stride=vid_stride)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\yolov5\utils\dataloaders.py", line 458, in init
assert cap.isOpened(), f"{st}Failed to open {s}"
^^^^^^^^^^^^^^
AssertionError: 1/1: https://youtu.be/qNEggYgsY0M?si=8ZOJr7HTNPcKx--F... Failed to open https://rr1---sn-ipoxu-un5e7.googlevideo.com/videoplayback?expire=1718870464&ei=YI1zZqrwMuzN2roPpcKr0A0&ip=2001%3Ab400%3Ae2d6%3A1675%3A3171%3A94f7%3A16d8%3A97ef&id=o-AJcMhuCchrU4niZjIUv6Gd8nk1avhQ1DlobLgVSmp80L&itag=18&source=youtube&requiressl=yes&xpc=EgVo2aDSNQ%3D%3D&mh=Zv&mm=31%2C26&mn=sn-ipoxu-un5e7%2Csn-ogul7nel&ms=au%2Conr&mv=m&mvi=1&pl=44&initcwndbps=982500&bui=AbKP-1MSYNWPqI6IaDHZoFajm7h7URFhgVTS80lZHe1nUoZjaQcZR0u9RIRidzaljFcBRYXIRyjk8Jho&spc=UWF9fy_IjYkzdE33U2Y1J9AXNGQ4uWDswT31WqaL-pTxF3_TpAzwxYPRIH2N&vprv=1&svpuc=1&mime=video%2Fmp4&ns=n-unt47rEMcb59I5p4YGJHQQ&rqh=1&cnr=14&ratebypass=yes&dur=601.420&lmt=1715885202750992&mt=1718848382&fvip=3&c=WEB&sefc=1&txp=6218224&n=niZkvTCch8pWhIMVBf&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cxpc%2Cbui%2Cspc%2Cvprv%2Csvpuc%2Cmime%2Cns%2Crqh%2Ccnr%2Cratebypass%2Cdur%2Clmt&sig=AJfQdSswRAIgZ8_wSb5aeRDIhlIqUHy_dQfzDFM9-lIO4Jg0HnrhrdkCIBHRsWIqtauEykKlxVErxCSBRmH4RKquHNzzLiOypm4b&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHlkHjAwRgIhAMhHdJSJahwI2N5UkNRnVbzvXIoDr-Ha7RzZSI0QzISEAiEApWosq3KAFcpUuEbUzPdqNb_AImQ9qp8aPaC350-j3xU%3D

Environment

YOLOv5 v7.0-326-gec331cbd
Python-3.12.4
torch-2.3.1+cpu CPU

Minimal Reproducible Example

No response

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@hsinpaul hsinpaul added the bug Something isn't working label Jun 20, 2024
Copy link
Contributor

👋 Hello @hsinpaul, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Requirements

Python>=3.8.0 with all requirements.txt installed including PyTorch>=1.8. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

YOLOv5 CI

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training, validation, inference, export and benchmarks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

Introducing YOLOv8 🚀

We're excited to announce the launch of our latest state-of-the-art (SOTA) object detection model for 2023 - YOLOv8 🚀!

Designed to be fast, accurate, and easy to use, YOLOv8 is an ideal choice for a wide range of object detection, image segmentation and image classification tasks. With YOLOv8, you'll be able to quickly and accurately detect objects in real-time, streamline your workflows, and achieve new levels of accuracy in your projects.

Check out our YOLOv8 Docs for details and get started with:

pip install ultralytics

@glenn-jocher
Copy link
Member

@hsinpaul hello,

Thank you for reaching out and providing details about the issue you're encountering. It looks like you're trying to use a YouTube URL as the source for detection, but OpenCV is unable to open the video stream.

To help us investigate further, could you please provide a minimal reproducible example? This will allow us to replicate the issue on our end. You can find guidance on how to create a minimal reproducible example here: Minimum Reproducible Example. This step is crucial for us to diagnose and resolve the problem effectively.

Additionally, please ensure that you are using the latest versions of the YOLOv5 repository and PyTorch. You can update your YOLOv5 repository with the following commands:

git pull
pip install -r requirements.txt

If the issue persists after updating, you might want to consider downloading the video locally and then running the detection script on the local file. Here is an example of how you can modify your command:

python detect.py --source path/to/local/video.mp4 --weights yolov5s.pt --data data/coco128.yaml --imgsz 640

This approach can help bypass any issues related to streaming from YouTube.

Please let us know if you have any further questions or if the issue persists after trying the above steps. We're here to help!

@hsinpaul
Copy link
Author

hsinpaul commented Jun 20, 2024

Hi @glenn-jocher
Thanks for your reply.

I downloaded the YouTube video and used the code below . and yolov5 was working fine, but the yolov5 still does not working with livesteam from YouTube . I think the problem is related to streaming Youtube.

python detect.py --source path/to/local/video.mp4 --weights yolov5s.pt --data data/coco128.yaml --imgsz 640

@glenn-jocher
Copy link
Member

Hi @hsinpaul,

Thank you for your follow-up and for confirming that YOLOv5 works with a downloaded YouTube video. It seems like the issue is indeed related to streaming directly from YouTube.

Streaming from YouTube can be tricky due to the way YouTube handles video URLs and streaming protocols. OpenCV's VideoCapture function may not support the dynamic URLs and authentication mechanisms that YouTube uses.

For live streaming, you might want to consider using a different approach. One common method is to use a tool like youtube-dl or yt-dlp to handle the YouTube stream and then pipe the video frames to YOLOv5. Here's an example of how you can achieve this:

  1. Install youtube-dl or yt-dlp:

    pip install yt-dlp
  2. Use yt-dlp to stream the video and pipe it to OpenCV:

    import cv2
    import subprocess
    
    # YouTube URL
    youtube_url = 'https://youtu.be/qNEggYgsY0M?si=8ZOJr7HTNPcKx--F'
    
    # Command to stream video using yt-dlp
    command = [
        'yt-dlp',
        '-o', '-',  # Output to stdout
        '-f', 'best',  # Select the best quality
        youtube_url
    ]
    
    # Open a subprocess to stream the video
    process = subprocess.Popen(command, stdout=subprocess.PIPE)
    
    # OpenCV VideoCapture from the subprocess stdout
    cap = cv2.VideoCapture(process.stdout)
    
    while cap.isOpened():
        ret, frame = cap.read()
        if not ret:
            break
        # Process the frame with YOLOv5
        # ...
    
        # Display the frame (optional)
        cv2.imshow('Frame', frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    
    cap.release()
    cv2.destroyAllWindows()

This script uses yt-dlp to stream the video and pipes the output to OpenCV for further processing. You can then integrate YOLOv5 detection within the loop where frames are read.

Please give this approach a try and let us know if it resolves the issue. If you encounter any further problems or have additional questions, feel free to ask. We're here to help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants