glenn-jocher
commited on
Commit
•
aff03be
1
Parent(s):
1f3e482
YouTube Bug Fix (#2818)
Browse filesFix for #2810
```shell
python detect.py --source 0
```
introduced by YouTube Livestream Detection PR #2752
- utils/datasets.py +6 -6
utils/datasets.py
CHANGED
@@ -272,15 +272,15 @@ class LoadStreams: # multiple IP or RTSP cameras
|
|
272 |
n = len(sources)
|
273 |
self.imgs = [None] * n
|
274 |
self.sources = [clean_str(x) for x in sources] # clean source names for later
|
275 |
-
for i, s in enumerate(sources):
|
276 |
-
# Start
|
277 |
print(f'{i + 1}/{n}: {s}... ', end='')
|
278 |
-
|
279 |
-
if 'youtube.com/' in url or 'youtu.be/' in url: # if source is YouTube video
|
280 |
check_requirements(('pafy', 'youtube_dl'))
|
281 |
import pafy
|
282 |
-
|
283 |
-
|
|
|
284 |
assert cap.isOpened(), f'Failed to open {s}'
|
285 |
w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
286 |
h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
|
|
272 |
n = len(sources)
|
273 |
self.imgs = [None] * n
|
274 |
self.sources = [clean_str(x) for x in sources] # clean source names for later
|
275 |
+
for i, s in enumerate(sources): # index, source
|
276 |
+
# Start thread to read frames from video stream
|
277 |
print(f'{i + 1}/{n}: {s}... ', end='')
|
278 |
+
if 'youtube.com/' in s or 'youtu.be/' in s: # if source is YouTube video
|
|
|
279 |
check_requirements(('pafy', 'youtube_dl'))
|
280 |
import pafy
|
281 |
+
s = pafy.new(s).getbest(preftype="mp4").url # YouTube URL
|
282 |
+
s = eval(s) if s.isnumeric() else s # i.e. s = '0' local webcam
|
283 |
+
cap = cv2.VideoCapture(s)
|
284 |
assert cap.isOpened(), f'Failed to open {s}'
|
285 |
w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
286 |
h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|