Skip to content

Python: YouTube livestream not working with Streamlink #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
devanshusharma19 opened this issue Apr 24, 2019 · 4 comments
Closed

Python: YouTube livestream not working with Streamlink #193

devanshusharma19 opened this issue Apr 24, 2019 · 4 comments

Comments

@devanshusharma19
Copy link

Expected behaviour

opencv working with youtube stream or youtube videos

Actual behaviour

actually it is not working it is showing error. I have tried on browser that link. It is working fine but in opencv is not working.

cv2.error: OpenCV(4.0.1) /io/opencv/modules/highgui/src/window.cpp:352: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'

Steps to reproduce

  • example code
import streamlink
import cv2

url = 'https://www.youtube.com/watch?v=bZ6NL59FMoc'

streams = streamlink.streams(url)
print(streams)
#cap = cv2.VideoCapture(streams["360p"].url)
cap = cv2.VideoCapture(streams["best"].url)

while True:
    ret, frame = cap.read()
    print(frame)
    cv2.imshow('frame', frame)

    if cv2.waitKey(1) & 0xff == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()
  • operating system

Ubuntu 18.04

  • architecture (e.g. x86)

64 bit
python 3.6

  • opencv-python version

opencv-python version 4.0.1

@Sushanti99
Copy link

Hello @devanshusharma19
This code works perfectly for me on Windows.
You can try manually fixing the height and width of the frame on Ubuntu I guess.

@native-api
Copy link
Contributor

Looks like a duplicate of #204

@fspider
Copy link

fspider commented Nov 22, 2019

Hello
With some youtube videos,this code works.
But this code not works with youtube live stream.

https://www.youtube.com/watch?v=17Deeq8N2e4
https://www.youtube.com/watch?v=1y5dcfnv-Ss
https://www.youtube.com/watch?v=tbLXWVhu8-Q

  1. Method
    vPafy = pafy.new(videoUrl)
    play = vPafy.getbest(preftype="mp4")
    return play.url

  2. Method
    streams = streamlink.streams(videoUrl)
    return streams["best"].url

All 2 Method not works.

The error screen like this

[ERROR:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap.cpp (116) cv::VideoCapture::open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.1.1) C:\projects\opencv-python\opencv\modules\videoio\src\cap_images.cpp:235: error: (-5:Bad argument) CAP_IMAGES: error, expected '0?[1-9][du]' pattern, got: https://manifest.googlevideo.com/api/manifest/hls_playlist/expire/1574433696/ei/QJ_XXfqBHNOTgQOBqpGwBw/ip/222.112.215.2/id/1EiC9bvVGnk.1/itag/96/source/yt_live_broadcast/requiressl/yes/ratebypass/yes/live/1/goi/160/sgoap/gir%3Dyes%3Bitag%3D140/sgovp/gir%3Dyes%3Bitag%3D137/hls_chunk_host/r5---sn-3u-bh2ll.googlevideo.com/playlist_type/DVR/initcwndbps/7760/mm/44/mn/sn-3u-bh2ll/ms/lva/mv/m/mvi/4/pl/23/dover/11/keepalive/yes/fexp/23842630/mt/1574412027/sparams/expire,ei,ip,id,itag,source,requiressl,ratebypass,live,goi,sgoap,sgovp,playlist_type/sig/ALgxI2wwRAIgG6xA4SgrD4PZGAfyup1jpL003-U3CQomrURDSKrCbZQCIElX0iQYvSGuZK-aoDsbY9Zv6SVTCNHOXGoUXhPCj0bN/lsparams/hls_chunk_host,initcwndbps,mm,mn,ms,mv,mvi,pl/lsig/AHylml4wRQIhAO1AS0iv1JaOu9igx-i3uGV-52UNCvd1Kd4Fu9SSC6OqAiAVjNjYYdr37w4Id111zdRsu8csAkIAfynBOk4SEO9f3w%3D%3D/playlist/index.m3u8 in function 'cv::icvExtractPattern'

Traceback (most recent call last):
File "D:/VideoFeedProcessing/VideoFeed/main.py", line 226, in
out = cv.VideoWriter('_output.avi', fourcc, 15, (ori_wid, ori_hei))
TypeError: must be real number, not tuple
[tcp @ 000001601c64fbc0] Connection to tcp://manifest.googlevideo.com:443 failed: Error number -138 occurred

@abhiTronix
Copy link
Contributor

abhiTronix commented Nov 22, 2019

@fspider This issue is not related to opencv-python as it not provide support for directly playing live-streaming youtube videos URLs. You can try another vidgear python video processing library for this purpose and the complete example code can be found here. Goodluck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants