Skip to content

Commit 65187f9

Browse files
committed
Download video if it doesn't exist
1 parent 605a1bd commit 65187f9

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

opencv/play-video.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import cv2
55
import os
66
import tempfile
7+
from subprocess import call
78

89
def screenshot(img):
910
dirname = tempfile._get_default_tempdir()
@@ -12,8 +13,14 @@ def screenshot(img):
1213
print('Screenshot %s' % filename)
1314
cv2.imwrite(filename, img)
1415

15-
# URL: https://www.youtube.com/watch?v=qRLbzpy1y8Y
1616
video = 'data/spain-vs-germany-2008.mp4'
17+
if not os.path.exists(video):
18+
if not os.path.exists(os.path.dirname(video)):
19+
os.mkdir(os.path.dirname(video))
20+
url = "https://www.youtube.com/watch?v=qRLbzpy1y8Y"
21+
print("Downloading video: %s" % url)
22+
call(["youtube-dl", url, "-o", video])
23+
print("Video saved: %s" % video)
1724
cap = cv2.VideoCapture(video)
1825

1926
while (True):

0 commit comments

Comments
 (0)