[英]Flask/Python - How can I populate an HTML page with live footage from multiple IP cameras?
I have a set of cameras and the URL's for each in RTSP format.我有一组摄像机和每个 RTSP 格式的 URL。 I have created a small script to parse the camera URL from the camera_config JSON file, but now I am not sure how to embed the videos into a grid layout on an HTML page.
我创建了一个小脚本来从 camera_config JSON 文件中解析相机 URL,但现在我不确定如何将视频嵌入到 Z4C4AD5FCA2E7A3F74DBB1CED003 页面上的网格布局中。 The script I wrote:
我写的脚本:
import json
from flask import flask
data = request.get_json()
file = open('cam_config.json',)
data = json.load(file)
for i in data['camStreams']:
i = data['camUrl']
@app.route("/livecams")
def livecams():
return render_template("live_cams.html", camUrl = i)
JSON File: JSON 文件:
{
"camDataDir":"/e/camData",
"playback": {
"playbackSpeed":"16.0"
},
"camStreams": [
{
"camName":"driveway",
"camUrl":"rtsp://admin:gf2UYmfH2kZDyEU@192.168.1.107:554/Streaming/Channels/3",
"camUrl4k":"rtsp://admin:gf2UYmfH2kZDyEU@192.168.1.107:554/Streaming/Channels/1",
"camUrl720p":"rtsp://admin:gf2UYmfH2kZDyEU@192.168.1.107:554/Streaming/Channels/3",
"camUrlMjpeg":"http://admin:gf2UYmfH2kZDyEU@192.168.1.107/ISAPI/Streaming/channels/102/httpPreview"
}
},
{
"camName": "backyard",
"camUrl": "rtsp://admin:jA6CL3G7Nukj7ST@192.168.1.166/cam/realmonitor?channel=1&subtype=02",
"camUrl4k": "rtsp://admin:jA6CL3G7Nukj7ST@192.168.1.166/cam/realmonitor?channel=1&subtype=01",
"camUrl720p": "rtsp://admin:jA6CL3G7Nukj7ST@192.168.1.166/cam/realmonitor?channel=1&subtype=02",
"camUrlMjpeg": "http://admin:jA6CL3G7Nukj7ST@192.168.1.166/cgi-bin/mjpg/video.cgi?channel=0&subtype=1"
}
}
]
}
HTML page (incomplete) HTML 页面(不完整)
{% extends "layout.html" %}
{% block content %}
<h1>Live Cams</h1>
<div class="grid"
<div class="container mt-3 mb-3">
<img src="{{ camUrl }}" alt="Cam 1" width="640" height="360">
</div>
{% endblock content %}
{% block script %}
{% endblock script %}
live_cams.html is the page for the live cam footage. live_cams.html 是现场摄像头画面的页面。 How would I go about modifying it to read each URL and output onto the HTML page as a grid?
我将如何将 go 修改为读取每个 URL 和 output 到 Z4C4AD5FCA2E7A1AA44 页面上的 Z4C4AD5FCA2E7A1AA44 页面As it is, I would have to hard code each individual camera in the HTML file but I want it to autopopulate when the HTML file is called.
事实上,我必须在 HTML 文件中对每个单独的相机进行硬编码,但我希望它在调用 HTML 文件时自动填充。 The intention is to simply update the cam_config with additional cameras and let it update dynamically.
目的是简单地使用额外的摄像头更新 cam_config 并让它动态更新。
Appreciate anyone who can help.感谢任何可以提供帮助的人。 Flask is new to me.
Flask 对我来说是新的。
You can pass the cam data directly into your render_template
and use a jinja for loop to output a container (or whatever you wish) per object in your camStreams
, eg:您可以将 cam 数据直接传递到您的
render_template
并使用 jinja for 循环到 output 一个容器(或任何您想要的)每个 object 在您的camStreams
中,例如:
Your view:您的看法:
@app.route("/livecams")
def livecams():
# Having this in the view means it will reload the config with each page refresh
file = open('cam_config.json',)
data = json.load(file)
return render_template("live_cams.html", cameras=data)
In your html:在您的 html 中:
{% for camera in cameras %}
<div class="container mt-3 mb-3">
<img src="{{ camera.camUrl }}" alt="{{camera.camName}}" width="640" height="360">
</div>
{% endfor %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.