YouTube live カメラ動画をopencvで表示
静岡県の薩埵峠のyoutubeライブ画像をopencv で表示する
当初は
YouTube動画をOpenCVでキャプチャするスクリプト
を参考に実行したがエラーとなる
YouTubeのライブ配信をOpenCVで再生する
も同様にエラーとなる
ChatGpt で
opencv でYouTubeライブカメラの画像を表示するPythonコード
を表示し実行したが
これもエラー
ERROR: Unable to extract uploader id; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see https://yt-dl.org/update on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.
Traceback (most recent call last):
File "/Users/snowpool/.pyenv/versions/3.10.6/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 815, in wrapper
return func(self, *args, **kwargs)
File "/Users/snowpool/.pyenv/versions/3.10.6/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 836, in __extract_info
ie_result = ie.extract(url)
File "/Users/snowpool/.pyenv/versions/3.10.6/lib/python3.10/site-packages/youtube_dl/extractor/common.py", line 534, in extract
ie_result = self._real_extract(url)
File "/Users/snowpool/.pyenv/versions/3.10.6/lib/python3.10/site-packages/youtube_dl/extractor/youtube.py", line 1794, in _real_extract
'uploader_id': self._search_regex(r'/(?:channel|user)/([^/?&#]+)', owner_profile_url, 'uploader id') if owner_profile_url else None,
File "/Users/snowpool/.pyenv/versions/3.10.6/lib/python3.10/site-packages/youtube_dl/extractor/common.py", line 1012, in _search_regex
raise RegexNotFoundError('Unable to extract %s' % _name)
youtube_dl.utils.RegexNotFoundError: Unable to extract uploader id; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see https://yt-dl.org/update on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/snowpool/aw10s/youtuvelive.py", line 36, in <module>
display_youtube_stream(youtube_url)
File "/Users/snowpool/aw10s/youtuvelive.py", line 11, in display_youtube_stream
info_dict = ydl.extract_info(url, download=False)
File "/Users/snowpool/.pyenv/versions/3.10.6/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 808, in extract_info
return self.__extract_info(url, ie, download, extra_info, process)
File "/Users/snowpool/.pyenv/versions/3.10.6/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 824, in wrapper
self.report_error(compat_str(e), e.format_traceback())
File "/Users/snowpool/.pyenv/versions/3.10.6/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 628, in report_error
self.trouble(error_message, tb)
File "/Users/snowpool/.pyenv/versions/3.10.6/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 598, in trouble
raise DownloadError(message, exc_info)
youtube_dl.utils.DownloadError: ERROR: Unable to extract uploader id; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see https://yt-dl.org/update on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.
となる
youtube_dlライブラリがYouTubeのビデオからアップローダーIDを抽出することができない
で検索
Pythonのパッケージyoutube_dlで、DownloadErrorが発生する。
を参考に
pip install yt-dlp
でインストールし
import youtube_dl
の代わりに
from yt_dlp import YoutubeDL
でインポート
import cv2
import youtube_dl
from yt_dlp import YoutubeDL
def display_youtube_stream(url):
ydl_opts = {
'format': 'best[ext=mp4]', # mp4 format, you can change this to other formats
'quiet': True,
}
with YoutubeDL() as ydl:
info_dict = ydl.extract_info(url, download=False)
video_url = info_dict['url']
cap = cv2.VideoCapture(video_url)
if not cap.isOpened():
print("Error: Could not open stream.")
exit()
while True:
ret, frame = cap.read()
if not ret:
print("Failed to grab frame.")
break
cv2.imshow('YouTube Live Stream', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
# Replace with your YouTube live stream URL
youtube_url = 'https://www.youtube.com/watch?v=6S4qvf97cbQ'
display_youtube_stream(youtube_url)
として保存
これで実行すると
YouTube live画像が表示されます
なお表示しているのは
LIVE】静岡市さった峠 交通の要衝