From 3fd23055bcd1c1473a05f87ad143f019a7b02207 Mon Sep 17 00:00:00 2001 From: Thomas Dannenberg Date: Sat, 30 Aug 2025 15:19:10 +0000 Subject: [PATCH] Kapitel 13/Tutorial.md aktualisiert --- Kapitel 13/Tutorial.md | 131 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 130 insertions(+), 1 deletion(-) diff --git a/Kapitel 13/Tutorial.md b/Kapitel 13/Tutorial.md index 96ed086..b801be5 100644 --- a/Kapitel 13/Tutorial.md +++ b/Kapitel 13/Tutorial.md @@ -606,4 +606,133 @@ Mit diesem Aufbau ist der **False-Pfad** fertig: Wenn die State-Datei fehlt oder - Es werden nur **neue VODs** heruntergeladen und hochgeladen. - Die State-Datei wird erweitert, ohne bestehende IDs zu überschreiben. - Logs bleiben konsistent, Doppel-Downloads werden vermieden. - - Jeder Node ist eindeutig benannt, was die Übersicht verbessert. \ No newline at end of file + - Jeder Node ist eindeutig benannt, was die Übersicht verbessert. + + --- +# 🧪 Abschnitt 4 – Analyse + + + --- + + + > [!NOTE] + > Wir verwenden in diesem Tutorial **keine KI‑Analyse**. Hierfür wird es ein **eigenes Tutorial** geben. Wir legen aber bereits alles so an, dass später keine Umbauten mehr nötig sind. + + + --- + + + ## Schritt 4.1 – Analyse‑Skript anlegen + **Ort:** Terminal im **Clipper‑LXC** → als Benutzer **`clipper`** + + + Öffne das Skript und trage den Inhalt ein: + + + ```bash + nano /srv/clipper/bin/clipper-analyze + ``` + + + Inhalt: + ```bash + #!/usr/bin/env bash + set -euo pipefail + . /etc/clipper/clipper.env + + + ID="${1:?need VOD id}" + + + VOD_IN_MP4="${CLIPPER_IN}/${ID}.mp4" + OUT_BASE="${CLIPPER_OUT}/${ID}" + ANALYSIS="${OUT_BASE}/analysis" + LOGDIR="${CLIPPER_LOG}/${ID}" + + + mkdir -p "$ANALYSIS" "$LOGDIR" + exec > >(tee -a "${LOGDIR}/analyze.log") 2>&1 + echo "== Analyze $ID ==" + + + # 1) Szenenwechsel + ffmpeg -hide_banner -loglevel error -i "${VOD_IN_MP4}" \ + -vf "scale=-2:360,select=gt(scene\,0.30),showinfo" -an -f null - \ + 2> "${LOGDIR}/sceneinfo.log" + + + # 2) Audio-Statistik + ffmpeg -hide_banner -loglevel error -i "${VOD_IN_MP4}" \ + -vn -ac 1 -ar 16000 \ + -af "astats=metadata=1:reset=2,ametadata=print:key=lavfi.astats.Overall.RMS_level" \ + -f null - \ + 2> "${LOGDIR}/astats.log" || true + + + # 3) Logs → candidates.json + ANALYSIS="$ANALYSIS" LOGDIR="$LOGDIR" python3 - <<'PY' + import os,re,json + out=os.environ["ANALYSIS"]; log=os.environ["LOGDIR"] + + + scene_ts=[] + with open(os.path.join(log,"sceneinfo.log"), errors="ignore") as f: + for line in f: + m=re.search(r"pts_time:([0-9]+(?:\.[0-9]+)?)", line) + if m: scene_ts.append(float(m.group(1))) + + + has_audio=False + ap=os.path.join(log,"astats.log") + if os.path.exists(ap): + with open(ap, errors="ignore") as f: + has_audio = "RMS_level" in f.read() + + + cands=[{ + "start": max(0.0,t-2.0), + "end": t+6.0, + "score": round(0.6+(0.1 if has_audio else 0),2), + "tags": ["scene-cut"] + (["audio-peak"] if has_audio else []) + } for t in scene_ts] + + + with open(os.path.join(out,"candidates.json"),"w",encoding="utf-8") as f: + json.dump(cands,f,ensure_ascii=False,indent=2) + print("Wrote", os.path.join(out,"candidates.json")) + PY + + + echo "== Done $ID ==" + ``` + + + Ausführbar machen: + ```bash + chmod +x /srv/clipper/bin/clipper-analyze + ``` + + + --- + + + ## Schritt 4.2 – n8n: Analyse starten + **Ort:** n8n‑Weboberfläche + + + **SSH Node – Analyze VOD** + - **Credentials:** `SSH Clipper` + - **Working Dir:** `/srv/clipper` + - **Command (Expression):** + ```js + {{`/srv/clipper/bin/clipper-analyze ${$json.data.id}`}} + ``` + + + --- + + + ## Ergebnis + - Für jedes neue VOD wird automatisch ein eigener Log‑Ordner erstellt. + - Die Analyse erzeugt pro VOD eine **`candidates.json`** mit Zeitfenstern. + - Abschnitt 5 nutzt diese JSON für den Schnitt.