在Google Colab上播放视频 [英] Playing videos on Google Colab
本文介绍了在Google Colab上播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用以下代码在Google Colab上播放YouTube视频,
I tried to use the following codes to play YouTube videos on Google Colab,
!pip install pytube==9.1.0
from pytube import YouTube
yt = YouTube('https://www.youtube.com/watch?v=-ncJV0tMAjE&t=72s')
yt对象的标题是
print(yt.title)
>> 作業2 第二題 強健控制:結構化不確定參數的Riccati equation
然后,我导入了cv2.
Then, I imported cv2.
import cv2
import numpy as np
cap = cv2.VideoCapture('作業2 第二題 強健控制:結構化不確定參數的Riccati equation.mp4')
while(cap.isOpened()):
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
但是,我总是收到一条错误消息,
However, I always got an error message as,
Runtime died. Autmatically restarting.
我该怎么办?
推荐答案
您需要获取视频的嵌入代码.
You need to get the embed code of your video.
from IPython.display import HTML
HTML('<iframe width="560" height="315" src="https://www.youtube.com/embed/lTTZ8PkQ_Pk" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>')
这篇关于在Google Colab上播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文