0

I am trying to get video from Youtube using Python 3.5, OpenCV 3.4.3 and Pafy 0.5.4. The problem is that cv2.VideoCapture(video_from_url) does not see the video from url. I also have seen this topic previously. Here is the code that works well if video_from_url variable is replaced with a path to video on my local PC.

import pafy
import cv2

url = 'https://www.youtube.com/watch?v=iCSd0slqzcQ&start_radio=1&list=RDiCSd0slqzcQ'

video_pafy = pafy.new(url)

video_from_url = video_pafy.getbest().url

cap = cv2.VideoCapture(video_from_url)

while True:

  ret, frame = cap.read()
  print(ret) # False

  """
  Further video processing
  """
Ankit
  • 31
  • 5
enoted
  • 577
  • 7
  • 21
  • You're not going to be able to work directly off that URL; the URL playback capability of OpenCV is quite limited, and that's also a very shaky way to get video and not guaranteed at all to continue to work. The best bet is to use that tool to download videos, and then play off the downloaded videos... – alkasm Sep 19 '18 at 16:45
  • It works for me correctly. – eyllanesc Sep 19 '18 at 18:16
  • @eyllanesc Which python and opencv versions are you using? – enoted Sep 19 '18 at 21:36
  • @YuriiM. opencv 3.4.3 pỳthon 3.7 – eyllanesc Sep 19 '18 at 21:42
  • 1
    @eyllanesc I've tried to run with python 3.7 and still unsuccessful. Did you build opencv from source or installed previously built binaries? – enoted Sep 20 '18 at 08:44

0 Answers0