-
-
Notifications
You must be signed in to change notification settings - Fork 242
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
How Get Frame from Youtube Live Stream #73
Comments
@fspider All these YouTube live video URLs are working fine with vidgear, Kindly install and test testing branch by strictly following steps:
sudo pip install -U opencv-python For more info., see issue #14
git clone https://github.com/abhiTronix/vidgear.git
cd vidgear
git checkout testing
sudo pip install .
cd
# import libraries
from vidgear.gears import CamGear
import cv2
stream = CamGear(source='https://youtu.be/17Deeq8N2e4', y_tube = True, logging=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. and see if it works, if not, then report here. Goodluck |
C:\Users\Codem>pip install vidgear After above install, i ran your code then i got this errorPS D:\VideoFeedProcessing\age-gender-detect> python .\c.py During handling of the above exception, another exception occurred: Traceback (most recent call last): During handling of the above exception, another exception occurred: Traceback (most recent call last): During handling of the above exception, another exception occurred: Traceback (most recent call last): During handling of the above exception, another exception occurred: Traceback (most recent call last): During handling of the above exception, another exception occurred: Traceback (most recent call last): |
@fspider you are still installing and using old vidgear binaries on your windows machine. Kindly run following commands in your Powershell to install latest vidgear binaries: wget https://github.com/abhiTronix/vidgear/archive/testing.zip -O testing.zip
Expand-Archive testing.zip
cd testing/vidgear-testing
pip install .
cd Or install it on Command Prompt with following command: powershell
wget https://github.com/abhiTronix/vidgear/archive/testing.zip -O testing.zip
Expand-Archive testing.zip
cd testing/vidgear-testing
pip install .
cd and also install latest pip install -U youtube-dl pafy Then run the example code, it must work and revert the results here. |
Thanks it works well. And can you tell me if it is possible to set parameters(resolution, frame rate) like this CamGear(source='https://youtu.be/17Deeq8N2e4', y_tube = True, logging=True, resolution=(320, 240), framerate=20).start() I have just tried but it not work |
@fspider Thanks for confirming.
Not possible is yet. I can surely add support for changing resolution directly but we cannot change framerate of a youtube video directly as it is not possible within pafy itself. But you can certainly use vidgear's powerful WriteGear API for saving video at desired resolution and framerate easily. Read it's Wiki Documentation for example code and other details. Goodluck. |
Thanks for your kindness. |
Not possible to change framerate of a YouTube video directly while reading with any python module available on the internet since Official YouTube API do not allow us to do this. |
Thanks. Then It is good with raw fps, |
@fspider I was looking at pafy docs and concluded that we can only set a limited number of pre-defined resolutions with Stream API for example: |
Thanks for you help! |
Hello. Please help me one more. |
cap = CamGear(source='videoUrl', y_tube = True, logging=True).start() # YouTube Video URL as input
# FPS:
fps = cap.framerate
#Width and height
ori_wid = cap.stream.get(cv2.CAP_PROP_FRAME_WIDTH)
ori_hei = cap.stream.get(cv2.CAP_PROP_FRAME_HEIGHT)
# to check output
print(fps)
print(ori_wid)
print(ori_hei) |
Hello
With some youtube videos,this code works.
But this code not works with these 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
Method
vPafy = pafy.new(videoUrl)
play = vPafy.getbest(preftype="mp4")
return play.url
Method
streams = streamlink.streams(videoUrl)
return streams["best"].url
cap = cv.VideoCapture(videoUrl)
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
The text was updated successfully, but these errors were encountered: