Skip to content
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

Problem with live youtube stream #239

Open
refigh opened this issue Jul 1, 2019 · 9 comments
Open

Problem with live youtube stream #239

refigh opened this issue Jul 1, 2019 · 9 comments

Comments

@refigh
Copy link

refigh commented Jul 1, 2019

Hi
I was able to use this tool to play YouTube video in Python 3+OpenCV 4.1. However, when I use URL of a live YouTube I get below error:

File "/usr/local/lib/python3.6/dist-packages/pafy/pafy.py", line 124, in new
return Pafy(url, basic, gdata, size, callback, ydl_opts)
File "/usr/local/lib/python3.6/dist-packages/pafy/backend_youtube_dl.py", line 29, in init
super(YtdlPafy, self).init(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/pafy/backend_shared.py", line 96, in init
self._fetch_basic()
File "/usr/local/lib/python3.6/dist-packages/pafy/backend_youtube_dl.py", line 47, in _fetch_basic
self._author = self._ydl_info['uploader']
KeyError: 'uploader'

tested live vide: "https://www.youtube.com/watch?v=YlksXBZbx8Y"
moreover, this command also generates same error:
sudo ytdl -b "https://www.youtube.com/watch?v=YlksXBZbx8Y"

Is there any support for live video?

@abhiTronix
Copy link

Test this: abhiTronix/vidgear#16 (comment) and drop a ⭐ if helped. Goodluck!

@dmarraud
Copy link

Hello, I am trying to use pafy and opencv to access youtube live streams. The first two or three seconds are grabbed correctly, then it freezes and next frames are grabbed after tens of seconds then freeze again, and so on. Beside this problem I would have expected a capture that takes the latest available image in the live stream whatever the grabbing rate, whereas current behavior seems to show that all frames in the stream have to be grabbed sequentially? Any ideas? Thanks!

@refigh
Copy link
Author

refigh commented Sep 22, 2019

frames in mpeg/h264 standard format stream are dependent on each other (they are not like independent images). So, if you lose one frame, next frame can not be decoded.
I had this problem too, not only with live youtube, but also with IP cameras, onan ARM board. I think the problem is that opencv does not use gpu (or cpu's internal decoder) to decode frames. I temporary solved my issue by reducing the FPS of my IP camera, but generally
you need to find another way (like read stream with VLC, gstream,..etc, and somehow pass the result to opencv)
see this : opencv/opencv#15545

@dmarraud
Copy link

Thanks for your answer! What is Strange is that it works perfectly well with non live YouTube videos.

@refigh
Copy link
Author

refigh commented Sep 22, 2019

because offline youtube is like file, you read offline, by your own speed, no packet is lost. but in online youtube, or IP-camera, you need to decode this frame, before losing next frame.

@dmarraud
Copy link

Yes it makes sense. Thanks. Thus, any other link to share that would show how to access decoded live streaming frames in opencv ? I searched different forums without success so far...

@refigh
Copy link
Author

refigh commented Sep 22, 2019

what is your platform? do you work on an ARM board, like Raspberry?

@dmarraud
Copy link

dmarraud commented Sep 22, 2019 via email

@refigh
Copy link
Author

refigh commented Sep 22, 2019

As I wrote, I recently learnt that opencv does not use GPU/internal decoder/encoder,... and you need to find a way to use them.
As far as I know, gstreamer and VLC use GPUs. I read somewhere (but will test this week myself) to use gstreamer and its python plugin. It means use a linux/windows tool like gstreamer to get the frames and decode them fast, then pass them to python+opencv with help of special plugin.

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

3 participants