python - OpenCV HLS youtube 流在几帧后停止
问题描述
我正在尝试让 Youtube 直播流与 openCV 一起使用,但在 10 帧后它只是停止并在 2 分钟后重新启动。
错误信息:
[tls @ 000001676fa27400] Unable to read from socket
[tls @ 000001676fa27400] Writing encrypted data to socket failed
[tls @ 000001676fa27400] Failed to send close message
使用的代码:
import cv2
import pafy
url = 'https://youtube.com/watch?v=51djMAqsmIQ'
vPafy = pafy.new(url)
play = vPafy.getbest()
print(play.url)
cap = cv2.VideoCapture(play.url)
while (True):
ret,frame = cap.read()
cv2.imshow('frame',frame)
if cv2.waitKey(20) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
解决方案
我也确实遇到了来自 youtube 的实时 HSL 流的问题。
我确实使用了解决方法:
https://github.com/streamlink/streamlink/issues/857
在这种情况下,我使用 streamlink 来制作文件 /tmp/stream. 使用 opencv 我正在读取文件 /tmp/stream..
(缺点:你必须停止流,否则文件会变大)
推荐阅读
- wpf - 如何使用按钮样式作为其他按钮的模板?
- macos - 在 MacOS 上使用 GPS 时出现错误“ld: library not found for -lSystem”
- android - 如何停止将焦点移到 Nativescript (Android) 中的 Enter 按键上?
- android - 如何在颤振中实现后台服务以从服务器获取数据?
- algorithm - 寻找集合中整数符号组合的算法,使得集合总和为 0
- java - 匿名类访问java中的局部变量
- arcore - 我无法在最新的 Sceneform SDK 中向 chromavideo 添加视频纹理
- python - 如何在 QtWidgets.QDialog 关闭事件中做某事
- python - 如何对与熊猫中另一列匹配的值求和?
- mysql - MYSQL:如何将变量插入表中,这取决于变量是否为空?