我和我的朋友正在建造一个小型漫游车,以带路为乐。我们正在通过创建一个将在Raspberry Pi上托管的网站进行处理,以便只有连接到同一wifi的人才能查看它(通过将pi的IP和端口输入到Web浏览器中)。现在,我正在使用flask托管网站。我的代码正在运行,当我在pi上打开flask应用程序时,我可以看到来自网络摄像头的视频供稿,但是当我在另一台设备上访问该网站时,会看到为该视频创建的纯灰色框放入(不包含Feed)。旁注:我们尝试了MJPEG拖缆并且可以使用,但我希望也能在页面上放置流动站的按钮和控件。这是我的python代码:
from flask import flask,render_template
app = flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
if __name__ == "__main__":
app.run(debug = True,host = "0.0.0.0",port = 80)
这是HTML代码(index.html):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Le Rover</title>
<style>
#container {
margin: 0px auto;
width: 500px;
height: 375px;
border: 10px #333 solid;
}
#videoElement {
width: 500px;
height: 375px;
background-color: #666;
}
#title {
text-align: center;
}
</style>
</head>
<body>
<h1 id="title">Mason and Keith's Rover</h1>
<div id="container">
<video autoplay="true" id="videoElement">
</video>
</div>
<script>
var video = document.querySelector("#videoElement");
if (navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia({ video: true })
.then(function (stream) {
video.srcObject = stream;
})
.catch(function (err0r) {
console.log("Something went wrong!");
});
}
</script>
</body>
</html>
上面的HTML,CSS和Javascript是从实时流媒体教程中获得的,因此我并不完全了解它的工作原理。我不确定是Java脚本还是python flask代码。如果您有解决方案,请回复。