Is it possible to stream video from https:// (e.g. YouTube) into python with OpenCV?

后端 未结 4 536
囚心锁ツ
囚心锁ツ 2020-12-13 20:09

This link has a tidy little example of how to use python\'s OpenCV library, cv2 to stream data from a camera into your python shell. I\'m looking to do some exp

4条回答
  •  余生分开走
    2020-12-13 21:05

    I've added Youtube URL source support in my VidGear Python Library that automatically pipelines YouTube Video into OpenCV by providing its URL only. Here is a complete python example:

    # import libraries
    from vidgear.gears import CamGear
    import cv2
    
    stream = CamGear(source='https://youtu.be/dQw4w9WgXcQ', y_tube =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

提交回复
热议问题