简体   繁体   English

Flask/Python - 如何使用来自多个 IP 摄像机的实时画面填充 HTML 页面?

[英]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.

相关问题 如何使用Python从多个IP摄像机流式传输视频 - How to stream videos from multiple IP cameras using Python 如何使用OpenCV捕获来自多台摄像机的实时视频? - How to use OpenCV to capture live video feed from multiple cameras? 如何通过 flask 应用程序访问 html 页面,然后从同一 Z319C34606A7D4A9C76 访问另一个 html 页面 - How can I access html page through flask app and then another html page from the same flask app Flask/Python - 我如何在 Flask 中运行这个 python 脚本并在 ZFC35FDC70D5FC69D256987A 页面中渲染 output - Flask/Python - How can I run this python script in Flask and render output in html page 如何从 Flask Select 下拉列表中的 model 填充数据? - How can I populate data from a model in Flask Select Dropdown? 如何使用带按钮的html页面和带python的flask在mongodb中搜索? - How can I search in mongodb using an html page with button and using flask with python? 如何为同一页面使用不同的变量返回 render_template() - flask python &amp; html - how can i do a return render_template() with different variables for the same page - flask python & html 使用Python,flask和SQLAlchemy如何将数据库查询的结果打印在HTML页面上? - Using Python, flask and SQLAlchemy How can I print on an HTML page the result of a DB query? 如何让我的 opencv wwebcam 显示画面更快? - How can i make my opencv wwebcam show footage faster? 如何使用正确的路由通过Flask显示HTML页面? - How can I use the correct routing to display an HTML page with Flask?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM