forked from andrew/karung-counting-feedmill-semarang
fix: clip timeout 600s + progress bar; occlusion tracking fix
- src/clip.py: default timeout 180->600s, add progress_cb callback - counter_dashboard.py: read MOTIONEYE_CLIP_TIMEOUT env, pass progress to clip_batch, expose stage/piece/total in /status & /pending - templates/history.html: render progress bar [███░░] 60% in running button - .env.example: add MOTIONEYE_CLIP_TIMEOUT=600 - src/stabilizer.py: max_hold_frames 10->25 (hold bbox ~1s during worker occlusion) - cfg/tracker.yaml: track_buffer 60->90 (FastTrack keeps lost track ~3.6s for re-ID) - tests/test_clip.py: update expected timeout to 600
This commit is contained in:
1 parent
1c5b460a48
commit
af27a4420e
8 files changed
+64
-14
No files matched your search
@@ -33,6 +33,7 @@ MOTIONEYE_URL=http://192.168.192.253:8765 # motionEye base URL for batch clip
|
||||
MOTIONEYE_CAMERA_ID=2 # motionEye camera id (1 = default camera)
|
||||
MOTIONEYE_CLIP_PAD=3 # seconds trimmed before/after the batch window (float)
|
||||
MOTIONEYE_OSD_ALIGN=1 # 1 = OCR-correct OSD clock drift at cut points, 0 = filename-based offsets only
|
||||
MOTIONEYE_CLIP_TIMEOUT=600 # ffmpeg timeout per piece in seconds (default 600)
|
||||
|
||||
# --- Deprecated: model pipeline mode now lives in config.yaml models.active_mode.
|
||||
# Dashboard switches persist there (atomic write, comments preserved) and apply
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
# Custom FastTrack config tuned for sack counting:
|
||||
# - track_buffer=60: hold lost tracks for 60 frames (~2.4s at 25fps)
|
||||
# - track_buffer=90: hold lost tracks for 90 frames (~3.6s at 25fps)
|
||||
# to survive worker occlusion
|
||||
# - new_track_thresh=0.3: harder to spawn duplicate IDs
|
||||
# - track_low_thresh=0.05: recover faint detections behind workers
|
||||
@@ -11,7 +11,7 @@ tracker_type: bytetrack
|
||||
track_high_thresh: 0.20
|
||||
track_low_thresh: 0.05
|
||||
new_track_thresh: 0.30
|
||||
track_buffer: 60
|
||||
track_buffer: 90
|
||||
match_thresh: 0.85
|
||||
fuse_score: true
|
||||
|
||||
|
||||
@@ -1699,10 +1699,23 @@ def _clip_job_worker(key, date, batch_number, start_iso, end_iso, motion_url,
|
||||
_unlink_quiet(out_path)
|
||||
_finish("error", f"Modul klip belum tersedia: {e}")
|
||||
return
|
||||
try:
|
||||
clip_timeout = int((os.getenv("MOTIONEYE_CLIP_TIMEOUT") or "600").strip())
|
||||
except (TypeError, ValueError):
|
||||
clip_timeout = 600
|
||||
def _progress(stage, current=0, total=0):
|
||||
with _CLIP_JOBS_LOCK:
|
||||
job = _CLIP_JOBS.get(key)
|
||||
if job:
|
||||
job["stage"] = stage
|
||||
job["piece"] = current
|
||||
job["total_pieces"] = total
|
||||
try:
|
||||
clip_batch(
|
||||
motion_url, camera_id, str(start_iso), str(end_iso), out_path,
|
||||
timeout=clip_timeout,
|
||||
pad_seconds=pad, align_osd=align,
|
||||
progress_cb=_progress,
|
||||
)
|
||||
except ClipError as ce:
|
||||
_unlink_quiet(out_path)
|
||||
@@ -1732,6 +1745,9 @@ def api_batch_clip_pending():
|
||||
"start_time": j.get("start_time", ""),
|
||||
"status": j.get("status", ""),
|
||||
"error": j.get("error", ""),
|
||||
"stage": j.get("stage", ""),
|
||||
"piece": j.get("piece", 0),
|
||||
"total_pieces": j.get("total_pieces", 0),
|
||||
}
|
||||
for j in _CLIP_JOBS.values()
|
||||
]
|
||||
@@ -1853,6 +1869,9 @@ def api_batch_clip_status(date, batch_number):
|
||||
"job": key,
|
||||
"error": job.get("error", ""),
|
||||
"elapsed": elapsed,
|
||||
"stage": job.get("stage", ""),
|
||||
"piece": job.get("piece", 0),
|
||||
"total_pieces": job.get("total_pieces", 0),
|
||||
}
|
||||
), 200
|
||||
|
||||
|
||||
+19
-2
@@ -257,13 +257,16 @@ def _run_ffmpeg(args: list, timeout: int):
|
||||
|
||||
|
||||
def clip_batch(motion_url: str, camera_id: int, start_iso: str, end_iso: str,
|
||||
out_path: str, timeout: int = 180,
|
||||
pad_seconds: float = 3.0, align_osd: bool = True) -> None:
|
||||
out_path: str, timeout: int = 600,
|
||||
pad_seconds: float = 3.0, align_osd: bool = True,
|
||||
progress_cb=None) -> None:
|
||||
"""List → cover → trim pieces → concat into out_path. Raises ClipError only.
|
||||
|
||||
pad_seconds widens the target window (trim a little before/after the
|
||||
batch). align_osd OCR-corrects the burned-in OSD clock at the cut
|
||||
points (media-vs-wall drift; ~1-2 s per probe, cached).
|
||||
progress_cb(stage: str, current: int = 0, total: int = 0) called at each
|
||||
major step: 'listing', 'probing', 'aligning', 'trimming', 'concat', 'done'.
|
||||
"""
|
||||
try:
|
||||
start = datetime.fromisoformat(start_iso)
|
||||
@@ -278,8 +281,12 @@ def clip_batch(motion_url: str, camera_id: int, start_iso: str, end_iso: str,
|
||||
os.makedirs(os.path.dirname(out_path), exist_ok=True)
|
||||
tmpdir = None
|
||||
try:
|
||||
if progress_cb:
|
||||
progress_cb("listing", 0, 0)
|
||||
movies = list_movies(motion_url, camera_id)
|
||||
|
||||
if progress_cb:
|
||||
progress_cb("probing", 0, len(movies))
|
||||
def probe(path):
|
||||
return probe_duration(_download_url(motion_url, camera_id, path))
|
||||
|
||||
@@ -288,11 +295,15 @@ def clip_batch(motion_url: str, camera_id: int, start_iso: str, end_iso: str,
|
||||
raise ClipError(_NO_CLIP_MSG)
|
||||
tmpdir = tempfile.mkdtemp(dir=os.path.dirname(out_path))
|
||||
pieces = []
|
||||
if progress_cb:
|
||||
progress_cb("trimming", 0, len(clips))
|
||||
for index, clip in enumerate(clips):
|
||||
piece = os.path.join(tmpdir, "piece_{:03d}.mp4".format(index))
|
||||
clip_url = _download_url(motion_url, camera_id, clip["path"])
|
||||
off0, off1 = clip["off0"], clip["off1"]
|
||||
if align_osd:
|
||||
if progress_cb:
|
||||
progress_cb("aligning", index + 1, len(clips))
|
||||
orig0, orig1 = off0, off1
|
||||
if index == 0:
|
||||
off0 = _align_offset(clip_url, off0, window_start,
|
||||
@@ -304,6 +315,8 @@ def clip_batch(motion_url: str, camera_id: int, start_iso: str, end_iso: str,
|
||||
off0, off1 = orig0, orig1
|
||||
print("[CLIP] align rejected (span < 1s); "
|
||||
"filename-based offsets kept.", flush=True)
|
||||
if progress_cb:
|
||||
progress_cb("trimming", index + 1, len(clips))
|
||||
_run_ffmpeg(
|
||||
_piece_argv(clip_url, off0, off1, piece),
|
||||
timeout,
|
||||
@@ -312,11 +325,15 @@ def clip_batch(motion_url: str, camera_id: int, start_iso: str, end_iso: str,
|
||||
if len(pieces) == 1:
|
||||
shutil.move(pieces[0], out_path)
|
||||
else:
|
||||
if progress_cb:
|
||||
progress_cb("concat", 0, 1)
|
||||
list_file = os.path.join(tmpdir, "concat.txt")
|
||||
with open(list_file, "w") as handle:
|
||||
for piece in pieces:
|
||||
handle.write("file '{}'\n".format(piece))
|
||||
_run_ffmpeg(_concat_argv(list_file, out_path), timeout)
|
||||
if progress_cb:
|
||||
progress_cb("done", 1, 1)
|
||||
except ClipError:
|
||||
raise
|
||||
except Exception as exc:
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@ Addresses four occlusion/flickering problems:
|
||||
1. Bbox jitter: raw detections jump 10-50px between frames.
|
||||
Fix: EMA (exponential moving average) on bbox coordinates.
|
||||
2. Bbox loss at line: worker's head/body blocks sack for 5-10 frames.
|
||||
Fix: hold last known smoothed bbox for `max_hold_frames` (10 frames).
|
||||
Fix: hold last known smoothed bbox for `max_hold_frames` (25 frames).
|
||||
3. Height expansion spike: worker body merges into sack bbox.
|
||||
Fix: clamp height expansion (`raw_h > smooth_h * max_h_ratio`).
|
||||
4. Height shrinkage collapse: worker head/shoulder covers bottom of sack.
|
||||
@@ -24,7 +24,7 @@ class BboxStabilizer:
|
||||
def __init__(
|
||||
self,
|
||||
ema_alpha: float = 0.35,
|
||||
max_hold_frames: int = 10,
|
||||
max_hold_frames: int = 25,
|
||||
max_height_ratio: float = 1.5,
|
||||
min_height_ratio: float = 0.70,
|
||||
) -> None:
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ Uses Ultralytics FastTrack which handles:
|
||||
- Re-identification of occluded tracks after reappearance
|
||||
|
||||
Our custom cfg/tracker.yaml tunes:
|
||||
- track_buffer=60 (hold lost tracks ~2.4s to survive worker occlusion)
|
||||
- track_buffer=90 (hold lost tracks ~3.6s to survive worker occlusion)
|
||||
- new_track_thresh=0.3 (prevent duplicate IDs from spawning)
|
||||
- active_occ_to_lost_thresh=15 (tolerate 15 occluded frames)
|
||||
"""
|
||||
|
||||
+19
-6
@@ -489,14 +489,17 @@
|
||||
return [key.slice(0, i), key.slice(i + 1)];
|
||||
}
|
||||
|
||||
function setClipJob(key, status, error, startTime, elapsed) {
|
||||
function setClipJob(key, status, error, startTime, elapsed, stage, piece, totalPieces) {
|
||||
const cur = clipJobs[key];
|
||||
clipJobs[key] = {
|
||||
status,
|
||||
error: error || '',
|
||||
start_time: startTime || (cur && cur.start_time) || rowStartTimes[key] || '',
|
||||
elapsed: (elapsed != null) ? elapsed : (cur && cur.elapsed) || 0,
|
||||
downloaded: cur ? !!cur.downloaded : false
|
||||
downloaded: cur ? !!cur.downloaded : false,
|
||||
stage: stage || (cur && cur.stage) || '',
|
||||
piece: (piece != null) ? piece : (cur && cur.piece) || 0,
|
||||
total_pieces: (totalPieces != null) ? totalPieces : (cur && cur.total_pieces) || 0
|
||||
};
|
||||
}
|
||||
|
||||
@@ -515,12 +518,21 @@
|
||||
}
|
||||
|
||||
function applyClipState(btn) {
|
||||
if (!btn || btn.dataset.busy === '1') return; // busy: leave the in-flight label alone
|
||||
if (!btn || btn.dataset.busy === '1') return;
|
||||
const job = clipJobs[clipKey(btn.dataset.date, btn.dataset.batch)];
|
||||
const state = job ? job.status : 'idle';
|
||||
let html, disabled = false;
|
||||
if (state === 'running') {
|
||||
html = `<i class="fa-solid fa-circle-notch fa-spin"></i> Memproses… ${job.elapsed || 0} dtk`;
|
||||
const stage = job.stage || '';
|
||||
const piece = job.piece || 0;
|
||||
const total = job.total_pieces || 0;
|
||||
let detail = `Memproses… ${job.elapsed || 0} dtk`;
|
||||
if (stage && total > 0) {
|
||||
const pct = Math.round((piece / total) * 100);
|
||||
const bar = '█'.repeat(Math.floor(pct / 10)) + '░'.repeat(10 - Math.floor(pct / 10));
|
||||
detail = `${stage} ${piece}/${total} [${bar}] ${pct}% · ${job.elapsed || 0} dtk`;
|
||||
}
|
||||
html = `<i class="fa-solid fa-circle-notch fa-spin"></i> ${detail}`;
|
||||
disabled = true;
|
||||
} else if (state === 'ready') {
|
||||
html = `<i class="fa-solid fa-download"></i> ${job.downloaded ? 'Unduh lagi' : 'Siap — unduh'}`;
|
||||
@@ -569,7 +581,7 @@
|
||||
const data = await res.json();
|
||||
if (!data || !data.success || !data.status) return;
|
||||
if (data.status === 'running') {
|
||||
if (typeof data.elapsed === 'number') clipJobs[k].elapsed = data.elapsed;
|
||||
setClipJob(k, 'running', '', null, data.elapsed, data.stage, data.piece, data.total_pieces);
|
||||
} else if (data.status === 'ready') {
|
||||
setClipJob(k, 'ready', '', null, 0);
|
||||
} else if (data.status === 'error') {
|
||||
@@ -591,7 +603,8 @@
|
||||
return; // running → running: keep locally ticking elapsed
|
||||
}
|
||||
setClipJob(k, j.status, j.error, j.start_time,
|
||||
j.status === 'running' ? clipElapsedFrom(j.start_time) : 0);
|
||||
j.status === 'running' ? clipElapsedFrom(j.start_time) : 0,
|
||||
j.stage, j.piece, j.total_pieces);
|
||||
});
|
||||
renderClipButtons();
|
||||
ensureClipTimers();
|
||||
|
||||
+1
-1
@@ -205,7 +205,7 @@ def test_clip_batch_single_piece_argv(monkeypatch, tmp_path):
|
||||
pad_seconds=0, align_osd=False)
|
||||
assert len(calls) == 1
|
||||
args, timeout = calls[0]
|
||||
assert timeout == 180
|
||||
assert timeout == 600
|
||||
piece = args[-1]
|
||||
assert args[:-1] == [
|
||||
"ffmpeg", "-y",
|
||||
|
||||
Reference in new issue
Block a user