如何在 google colab 中播放 mp4 视频 [英] how play mp4 video in google colab
本文介绍了如何在 google colab 中播放 mp4 视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 content/video.mp4
如果我想在不下载的情况下在 google colab 中播放视频,¿我应该使用什么代码在我的 jupyter notebook 中打开一种视频播放器?
if I wanted to play the video in google colab without downloading , ¿what code I should use to open a kind of video player in my jupyter notebook?
推荐答案
代码如下
from IPython.display import HTML
from base64 import b64encode
mp4 = open('video.mp4','rb').read()
data_url = "data:video/mp4;base64," + b64encode(mp4).decode()
HTML("""
<video width=400 controls>
<source src="%s" type="video/mp4">
</video>
""" % data_url)
您可以在 colab 笔记本中测试它此处.
You can test it in a colab notebook here.
为了支持大的 vdo 文件,我编写了一个库上传到 Google Drive 并将其设置为公开.然后使用返回的 URL 显示视频.
To support a big vdo file, I write a library to upload to Google Drive and set it public. Then use the returned URL to display the video.
!pip install -U kora
from kora.drive import upload_public
url = upload_public('video.mp4')
# then display it
from IPython.display import HTML
HTML(f"""<video src={url} width=500 controls/>""")
这篇关于如何在 google colab 中播放 mp4 视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文