Kapitel 13/Tutorial.md aktualisiert

This commit is contained in:
2025-09-15 19:10:07 +00:00
parent 2bb3734fab
commit bde9dc1f3b

View File

@@ -844,113 +844,112 @@ Das folgende Schaubild zeigt dir die konkrete Verkabelung
## Schritt 4.1 AnalyseSkript anlegen ## Schritt 4.1 AnalyseSkript anlegen
**Ort:** Terminal im **ClipperLXC** → als Benutzer **`clipper`** **Ort:** Terminal im **ClipperLXC** → als Benutzer **`clipper`**
Öffne das Skript und trage den Inhalt ein: Öffne die Datei und ge den Inhalt ein:
```bash ```bash
nano /srv/clipper/bin/vod-analyze nano /srv/clipper/bin/vod-analyze # (dieses Skript wird das VOD analysieren und candidates.json erzeugen)
``` ```
Inhalt: Inhalt:
```bash ```bash
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail set -euo pipefail
. /etc/clipper/clipper.env . /etc/clipper/clipper.env
ID="${1:?need VOD id}" ID="${1:?need VOD id}"
VOD_IN_MP4="${CLIPPER_IN}/${ID}.mp4" VOD_IN_MP4="/srv/clipper/temp/${ID}.mp4" # temporäre Datei (vom VOD aus NC heruntergeladen)
OUT_BASE="${CLIPPER_OUT}/${ID}" OUT_BASE="${CLIPPER_OUT}/${ID}"
ANALYSIS="${OUT_BASE}/analysis" ANALYSIS="${OUT_BASE}/analysis"
LOGDIR="${CLIPPER_LOG}/${ID}" LOGDIR="${CLIPPER_LOG}/${ID}"
mkdir -p "$ANALYSIS" "$LOGDIR" mkdir -p "$ANALYSIS" "$LOGDIR"
exec > >(tee -a "${LOGDIR}/analyze.log") 2>&1 exec > >(tee -a "${LOGDIR}/analyze.log") 2>&1
echo "== Analyze $ID ==" echo "== Analyze $ID =="
# 1) Szenenwechsel # 1) Szenenwechsel
ffmpeg -hide_banner -loglevel error -i "${VOD_IN_MP4}" \ ffmpeg -hide_banner -loglevel error -i "${VOD_IN_MP4}" \
-vf "scale=-2:360,select=gt(scene\,0.30),showinfo" -an -f null - \ -vf "scale=-2:360,select=gt(scene\,0.30),showinfo" -an -f null - \
2> "${LOGDIR}/sceneinfo.log" 2> "${LOGDIR}/sceneinfo.log"
# 2) Audio-Statistik # 2) Audio-Statistik
ffmpeg -hide_banner -loglevel error -i "${VOD_IN_MP4}" \ ffmpeg -hide_banner -loglevel error -i "${VOD_IN_MP4}" \
-vn -ac 1 -ar 16000 \ -vn -ac 1 -ar 16000 \
-af "astats=metadata=1:reset=2,ametadata=print:key=lavfi.astats.Overall.RMS_level" \ -af "astats=metadata=1:reset=2,ametadata=print:key=lavfi.astats.Overall.RMS_level" \
-f null - \ -f null - \
2> "${LOGDIR}/astats.log" || true 2> "${LOGDIR}/astats.log" || true
# 3) Logs → candidates.json # 3) Logs → candidates.json
ANALYSIS="$ANALYSIS" LOGDIR="$LOGDIR" python3 - <<'PY' ANALYSIS="$ANALYSIS" LOGDIR="$LOGDIR" python3 - <<'PY'
import os,re,json import os,re,json
out=os.environ["ANALYSIS"]; log=os.environ["LOGDIR"] out=os.environ["ANALYSIS"]; log=os.environ["LOGDIR"]
scene_ts=[] scene_ts=[]
with open(os.path.join(log,"sceneinfo.log"), errors="ignore") as f: with open(os.path.join(log,"sceneinfo.log"), errors="ignore") as f:
for line in f: for line in f:
m=re.search(r"pts_time:([0-9]+(?:\.[0-9]+)?)", line) m=re.search(r"pts_time:([0-9]+(?:\.[0-9]+)?)", line)
if m: scene_ts.append(float(m.group(1))) if m: scene_ts.append(float(m.group(1)))
has_audio=False has_audio=False
ap=os.path.join(log,"astats.log") ap=os.path.join(log,"astats.log")
if os.path.exists(ap): if os.path.exists(ap):
with open(ap, errors="ignore") as f: with open(ap, errors="ignore") as f:
has_audio = "RMS_level" in f.read() has_audio = "RMS_level" in f.read()
cands=[{ cands=[{
"start": max(0.0,t-2.0), "start": max(0.0,t-2.0),
"end": t+6.0, "end": t+6.0,
"score": round(0.6+(0.1 if has_audio else 0),2), "score": round(0.6+(0.1 if has_audio else 0),2),
"tags": ["scene-cut"] + (["audio-peak"] if has_audio else []) "tags": ["scene-cut"] + (["audio-peak"] if has_audio else [])
} for t in scene_ts] } for t in scene_ts]
with open(os.path.join(out,"candidates.json"),"w",encoding="utf-8") as f: with open(os.path.join(out,"candidates.json"),"w",encoding="utf-8") as f:
json.dump(cands,f,ensure_ascii=False,indent=2) json.dump(cands,f,ensure_ascii=False,indent=2)
print("Wrote", os.path.join(out,"candidates.json")) print("Wrote", os.path.join(out,"candidates.json"))
PY PY
echo "== Done $ID ==" echo "== Done $ID =="
```
Ausführbar machen: # cleanup temp VOD
```bash echo "== Cleanup: remove temp file $VOD_IN_MP4 =="
chmod +x /srv/clipper/bin/clipper-analyze rm -f "$VOD_IN_MP4"
``` ```
--- ---
## Schritt 4.2 n8n: Analyse starten ## Schritt 4.2 n8n: Analyse starten
**Ort:** n8nWeboberfläche **Ort:** n8nWeboberfläche
**SSH Node Analyze VOD** **SSH Node Analyze VOD**
- **Credentials:** `SSH Clipper` - **Credentials:** `SSH Clipper`
- **Working Dir:** `/srv/clipper` - **Working Dir:** `/srv/clipper`
- **Command (Expression):** - **Command (Expression):**
```js ```js
{{`/srv/clipper/bin/vod-analyze ${$json.data.id}`}} {{`/srv/clipper/bin/vod-analyze ${$json.data.id}`}}
``` ```
--- ---
## Ergebnis ## Ergebnis