Show real pipeline FPS and stream resolution from live metadata
- Counter writes stream_meta.json with processing FPS and frame dimensions - Dashboard reads it instead of static defaults
This commit is contained in:
1 parent
1ca458f4e4
commit
ea1f376e1f
2 files changed
+35
-2
No files matched your search
+18
-2
@@ -35,6 +35,7 @@ CURRENT_BATCH_PATH = os.getenv("STATE_FILE", os.getenv("CURRENT_BATCH_PATH", f"{
|
||||
CUTOFF_TIME = os.getenv("CUTOFF_TIME", os.getenv("DAILY_CUTOFF_TIME", "06:00"))
|
||||
|
||||
LIVE_STREAM_FRAME_PATH = os.getenv("LIVE_STREAM_FRAME_PATH", "/dev/shm/feedmill/live_frame.jpg")
|
||||
LIVE_STREAM_META_PATH = os.getenv("LIVE_STREAM_META_PATH", "/dev/shm/feedmill/stream_meta.json")
|
||||
|
||||
SITE_NAME = os.getenv("SITE_NAME", "LIVE")
|
||||
CAMERA_NAME = os.getenv("CAMERA_NAME", "")
|
||||
@@ -159,6 +160,21 @@ def _send_counter_command(endpoint, data=b"", headers=None):
|
||||
return {"success": False, "error": str(e)}, 500
|
||||
|
||||
|
||||
|
||||
def _read_stream_meta():
|
||||
fps = STREAM_FPS_DISPLAY
|
||||
res = STREAM_RESOLUTION_DISPLAY
|
||||
try:
|
||||
with open(LIVE_STREAM_META_PATH) as f:
|
||||
meta = json.load(f)
|
||||
if meta.get("fps"):
|
||||
fps = str(meta["fps"])
|
||||
if meta.get("width") and meta.get("height"):
|
||||
res = f"{meta['width']}x{meta['height']}"
|
||||
except (OSError, ValueError, KeyError, TypeError):
|
||||
pass
|
||||
return fps, res
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
return render_template(
|
||||
@@ -166,8 +182,8 @@ def index():
|
||||
site_name=SITE_NAME,
|
||||
camera_name=CAMERA_NAME,
|
||||
cutoff_time=CUTOFF_TIME,
|
||||
stream_fps=STREAM_FPS_DISPLAY,
|
||||
stream_resolution=STREAM_RESOLUTION_DISPLAY,
|
||||
stream_fps=_read_stream_meta()[0],
|
||||
stream_resolution=_read_stream_meta()[1],
|
||||
stream_accuracy=STREAM_ACCURACY_PCT,
|
||||
batch_mode=BATCH_MODE,
|
||||
)
|
||||
|
||||
@@ -12,6 +12,7 @@ import os
|
||||
import signal
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
from collections import deque
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
@@ -107,6 +108,9 @@ LIVE_STREAM_ENABLED = os.getenv("LIVE_STREAM_ENABLED", "false").lower() == "true
|
||||
LIVE_STREAM_FRAME_PATH = os.getenv(
|
||||
"LIVE_STREAM_FRAME_PATH", "/dev/shm/feedmill/live_frame.jpg"
|
||||
)
|
||||
LIVE_STREAM_META_PATH = os.getenv(
|
||||
"LIVE_STREAM_META_PATH", "/dev/shm/feedmill/stream_meta.json"
|
||||
)
|
||||
LIVE_STREAM_QUALITY = int(os.getenv("LIVE_STREAM_QUALITY", "75"))
|
||||
LIVE_STREAM_EVERY_N = int(os.getenv("LIVE_STREAM_EVERY_N", "2"))
|
||||
|
||||
@@ -1382,6 +1386,8 @@ def run():
|
||||
session_start = time.time()
|
||||
frame_idx = 0
|
||||
inf_ms = 0.0
|
||||
prev_frame_time = time.monotonic()
|
||||
proc_fps = 0.0
|
||||
prev_gray = None
|
||||
video_writer = None
|
||||
crossing_times = deque()
|
||||
@@ -1797,6 +1803,17 @@ def run():
|
||||
with open(tmp_path, "wb") as f:
|
||||
f.write(jpeg.tobytes())
|
||||
os.replace(tmp_path, LIVE_STREAM_FRAME_PATH)
|
||||
now_mono = time.monotonic()
|
||||
dt = now_mono - prev_frame_time
|
||||
if dt > 0:
|
||||
inst = 1.0 / dt
|
||||
proc_fps = (proc_fps * 0.9 + inst * 0.1) if proc_fps else inst
|
||||
prev_frame_time = now_mono
|
||||
try:
|
||||
with open(LIVE_STREAM_META_PATH, "w") as mf:
|
||||
json.dump({"fps": round(proc_fps, 1), "width": w, "height": h}, mf)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
Reference in new issue
Block a user