OpenCV capture online video for further processing without downloading the file with Python

后端 未结 3 1301
时光取名叫无心
时光取名叫无心 2020-12-10 20:52

Given its link, I\'d like to capture an online video (say from YouTube) for further processing without downloading it on the disk. What I mean by this is th

3条回答
  •  再見小時候
    2020-12-10 21:43

    Using pafy you can have a more elegant solution:

    import cv2
    import pafy
    
    url = "https://www.youtube.com/watch?v=NKpuX_yzdYs"
    video = pafy.new(url)
    best = video.getbest(preftype="mp4")
    
    capture = cv2.VideoCapture()
    capture.open(best.url)
    
    success,image = capture.read()
    
    while success:
        cv2.imshow('frame', image)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    
        success,image = capture.read()
    
    cv2.destroyAllWindows()
    capture.release()
    

提交回复
热议问题