这是一些安全问题的组合。现代浏览器禁止使用本地数据(在这种情况下是本地字幕文件),而Colab则防止您通过“不安全”的http
协议渲染嵌入式视频。因此,为了显示带字幕的视频,您需要创建一个iframe
并将通过https
提供的视频(包括视频和字幕)嵌入其中。
您可以通过创建以下内容的单元格来测试此功能:
%%html
<iframe width="800" height="500" src="https://iandevlin.com/html5/webvtt-example.html"
frameborder="0" allow="encrypted-media;" allowfullscreen />
所以我认为,您需要创建一个自签名证书,将其添加到浏览器中使其合法化,运行一个TLS Web服务器在线程中以不阻塞笔记本电脑,创建一个带有<video>
标记的小型HTML文件,该(HTML文件)您的Web服务器将通过HTTPS提供,并且其URL将是笔记本电脑中<iframe>
的源。哇,这真的很复杂。
如果我们尝试将完整的HTML加载到一个具有在非本地存储的视频+轨道资产的iframe
中,这些工作:
%%html
<iframe width="800" height="500" src="https://iandevlin.com/html5/webvtt-example.html"
frameborder="0" allow="encrypted-media;" allowfullscreen />
或者
HTML("""<iframe width="800" height="500" src="https://iandevlin.com/html5/webvtt-example.html"
frameborder="0" allow="encrypted-media;" allowfullscreen /> """)
[输出]:
![enter image description here](https://istack.dev59.com/ua6xYl.webp)
但是当你尝试从https://iandevlin.com/html5/webvtt-example.html获取HTML,并通过srcdoc
将其加载到iframe
中时,它无法加载字幕:
%%html
<iframe width="800" height="500"
srcdoc='
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<title>WebVTT Video Subtitles Example for Chrome</title>
<meta name="keywords" content="webvtt,webvtt example,chrome,html5" />
<meta name="description" content="Sample HTML5 code that shows how Chrome supports WebVTT subtitles" />
<style>
body {
padding:10px;
font-size:80%;
font-family:verdana, serif;
}
figure { margin:30px 0; }
</style>
</head>
<body>
<header>
<h1>WebVTT Video Subtitles Example for Chrome</h1>
<p><a href="http://www.iandevlin.com/blog/2012/06/html5/google-chrome-supports-webvtt-subtitles">Read the full article</a></p>
<p>To view this in Google Chrome, you must first enable the <code>track</code> element:</p>
<ol>
<li>Go to the configuration tools in Chrome by typing <code>chrome:flags</code> in the address bar</li>
<li>Search for "Enable the <track> element" and activate it</li>
<li>Restart the browser</li>
</ol>
</header>
<figure>
<video controls preload="metadata" poster="http://html5multimedia.com/media/elephants-dream.title.jpg" width="422" height="253">
<source src="http://html5multimedia.com/media/elephants-dream-medium.webm" type="video/webm">
<track label="English subtitles" kind="subtitles" srclang="en" src="https://iandevlin.com/html5/english-subtitles.vtt" default>
</video>
<figcaption>
<small><a href="http://www.elephantsdream.org">Elephant's Dream</a> – © copyright 2006, Blender Foundation / Netherlands Media Art Institute</small>
</figcaption>
</figure>
</body>
</html>' />
仔细查看控制台,根据@atalay-k的评论,你会看到:
试图从URL about:srcdoc加载URL https://iandevlin.com/html5/english-subtitles.vtt,这是一次不安全的尝试。域名、协议和端口必须匹配。
这似乎是一个麻烦的问题,来源于在HTML视频中加载字幕时出现的安全错误