Reputation: 363
I am trying a basic example of displaying a youtube video using opencv, and I seem to get 50% or less of the framerate as in the browser. Eventually I want to make a real-time computer vision application from youtube streams (well, a fixed delay is fine, but I want it to be able to keep up), and so if just displaying a video is slow, I'm not sure how that is going to happen. Does anyone know which part of this is slow? And is there a way to speed it up?
import cv2
import pafy
import youtube_dl
url = 'https://youtu.be/1AbfRENy3OQ'
urlPafy = pafy.new(url)
videoplay = urlPafy.getbest()
cap = cv2.VideoCapture(videoplay.url)
while(True):
# Capture image frame-by-frame
ret, frame = cap.read()
# Display the resulting frame
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
Upvotes: 0
Views: 318
Reputation: 363
Turns out there was a bug in youtube_dl: https://github.com/ytdl-org/youtube-dl/issues/29326 that essentially caused youtube to throttle the connection.
Upvotes: 0