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

后端 未结 3 1303
时光取名叫无心
时光取名叫无心 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:38

    First of all Update youtube-dl using the command pip install -U youtube-dl

    Then use my VidGear Python Library, then automates the pipelining of YouTube Video using its URL address only. Here's a complete python example:

    # import libraries
    from vidgear.gears import CamGear
    import cv2
    
    stream = CamGear(source='https://youtu.be/dQw4w9WgXcQ', y_tube =True,  time_delay=1, logging=True).start() # YouTube Video URL as input
    
    # infinite loop
    while True:
    
        frame = stream.read()
        # read frames
    
        # check if frame is None
        if frame is None:
            #if True break the infinite loop
            break
    
        # do something with frame here
    
        cv2.imshow("Output Frame", frame)
        # Show output window
    
        key = cv2.waitKey(1) & 0xFF
        # check for 'q' key-press
        if key == ord("q"):
            #if 'q' key-pressed break out
            break
    
    cv2.destroyAllWindows()
    # close output window
    
    stream.stop()
    # safely close video stream.
    

    Code Source

    If still get some error, raise an issue here in its GitHub repo.

提交回复
热议问题