2

I used youtube-dl to get the direct link and fed it to the VideoCapture function but it's unable to read it.

def videoUrl(vidurl):
  with youtube_dl.YoutubeDL(dict(forceurl=True)) as ydl:
    r = ydl.extract_info(vidurl, download=False)
  urlList = list(filter(lambda item: item['ext'] == 'mp4' and item['format_note']=='360p', r['formats']))
  url = urlList[0]['url']
  return url
url = videoUrl('https://youtu.be/Zv11L-ZfrSg')
print(url)
cap=cv2.VideoCapture(url)
succ, frame = cap.read()
print(succ)

Output:

https://rr5---sn-ci5gup-cags.googlevideo.com/videoplayback?expire=1663552781&ei=rXgnY7OMAr6J_9EPvo-J6A8&ip=35.245.37.143&id=o-AMOfn5poZclrb4XygNf_fVdBLN7bYM1oFyyHT6qq9baI&itag=396&aitags=133,134,135,136,137,160,242,243,244,247,248,271,278,313,394,395,396,397,398,399,400,401,571&source=youtube&requiressl=yes&vprv=1&mime=video/mp4&ns=hmKzaLHbydm6DqqwqJSpk-wI&gir=yes&clen=35032048&dur=987.133&lmt=1648295005031855&keepalive=yes&fexp=24001373,24007246&c=WEB&rbqsm=fr&txp=4531432&n=KHMl7qz6AZjwBQ42&sparams=expire,ei,ip,id,aitags,source,requiressl,vprv,mime,ns,gir,clen,dur,lmt&sig=AOq0QJ8wRQIgS83pxuiS_nTQwm1bQqPMmqARiL__pBsCLCkHk-VGn8wCIQCieZlzAgoAs3oVjL-_LME_LQO-5UkIm5bdIO4mLdeutg%3D%3D&redirect_counter=1&rm=sn-p5qe7s7z&req_id=11d038818408a3ee&cms_redirect=yes&cmsv=e&ipbypass=yes&mh=O0&mip=2401:4900:33b9:d505:bbc1:9bb3:783d:f56&mm=31&mn=sn-ci5gup-cags&ms=au&mt=1663530663&mv=u&mvi=5&pl=48&lsparams=ipbypass,mh,mip,mm,mn,ms,mv,mvi,pl&lsig=AG3C_xAwRQIgbJY67vqv8sjjUhvyzPwEEgMgfjPLopTPzj5Ec6TaI1ICIQCzceH2B8P-8XfZvIeKxDAhXNrmwrQXdiJHy5mV-jn2yA%3D%3D
False

So what am I doing wrong ?

theunreal
  • 21
  • 2
  • print the url you're feeding to VideoCapture, show us that url – Christoph Rackwitz Sep 18 '22 at 19:47
  • I have added that in the question – theunreal Sep 18 '22 at 20:15
  • 1
    The video codec of `urlList[0]` is AV1. AV1 codec is not supported by your version of OpenCV. Try: `urlList = list(filter(lambda item: item['ext'] == 'mp4' and item['format_note']=='360p' and item['vcodec'][0:4]!='av01', r['formats']))` – Rotem Sep 18 '22 at 20:36
  • 1
    I'm pulling from that url... VideoCapture claims to be able to open it, but then chokes on the AV1 stream that's being served (I don't have hardware decoding). that error is familiar... ( https://forum.opencv.org/t/error-your-platform-doesnt-suppport-hardware-accelerated-av1-decoding-when-i-use-cv2-videocapture/9605 and https://github.com/opencv/opencv/issues/11389 ) so that appears fixed but not yet released. I'd expect the next release sometime in october. you _can_ use the git head revision, build opencv yourself, and try that. -- or what Rotem said, pick a different stream for that video – Christoph Rackwitz Sep 18 '22 at 21:50

0 Answers0