Kapitel 13/Tutorial.md aktualisiert
This commit is contained in:
@@ -801,88 +801,85 @@ Das folgende Schaubild zeigt dir die konkrete Verkabelung
|
||||
|
||||
```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_OUT}/${ID}/original/${ID}.mp4"
|
||||
OUT_BASE="${CLIPPER_OUT}/${ID}"
|
||||
ANALYSIS="${OUT_BASE}/analysis"
|
||||
LOGDIR="${CLIPPER_LOG}/${ID}"
|
||||
VOD_IN_MP4="${CLIPPER_OUT}/${ID}/original/${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 =="
|
||||
mkdir -p "$ANALYSIS" "$LOGDIR"
|
||||
exec > >(tee -a "${LOGDIR}/analyze.log") 2>&1
|
||||
echo "== Analyze $ID =="
|
||||
|
||||
# 1) Szenenwechsel
|
||||
echo "[FFMPEG] Szenewechselanalyse läuft..."
|
||||
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"
|
||||
echo "[FFMPEG] Szenewechselanalyse läuft..."
|
||||
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
|
||||
echo "[FFMPEG] Audiostatistik läuft..."
|
||||
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
|
||||
echo "[FFMPEG] Audiostatistik läuft..."
|
||||
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, sys
|
||||
from datetime import datetime
|
||||
ANALYSIS="$ANALYSIS" LOGDIR="$LOGDIR" python3 - <<'PY'
|
||||
import os, re, json, sys
|
||||
from datetime import datetime
|
||||
|
||||
def log(msg):
|
||||
timestamp = datetime.now().strftime("%F %T")
|
||||
print(f"[PY] [{timestamp}] {msg}")
|
||||
def log(msg):
|
||||
timestamp = datetime.now().strftime("%F %T")
|
||||
print(f"[PY] [{timestamp}] {msg}")
|
||||
|
||||
out = os.environ["ANALYSIS"]
|
||||
logdir = os.environ["LOGDIR"]
|
||||
out = os.environ["ANALYSIS"]
|
||||
logdir = os.environ["LOGDIR"]
|
||||
|
||||
scene_ts = []
|
||||
log("Lese sceneinfo.log...")
|
||||
try:
|
||||
with open(os.path.join(logdir, "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)))
|
||||
except Exception as e:
|
||||
log(f"Fehler beim Lesen von sceneinfo.log: {e}")
|
||||
sys.exit(1)
|
||||
scene_ts = []
|
||||
log("Lese sceneinfo.log...")
|
||||
try:
|
||||
with open(os.path.join(logdir, "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)))
|
||||
except Exception as e:
|
||||
log(f"Fehler beim Lesen von sceneinfo.log: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
log(f"{len(scene_ts)} Szenenwechsel gefunden.")
|
||||
log(f"{len(scene_ts)} Szenenwechsel gefunden.")
|
||||
|
||||
has_audio = False
|
||||
ap = os.path.join(logdir, "astats.log")
|
||||
if os.path.exists(ap):
|
||||
log("Prüfe astats.log auf Audiodaten...")
|
||||
with open(ap, errors="ignore") as f:
|
||||
has_audio = "RMS_level" in f.read()
|
||||
has_audio = False
|
||||
ap = os.path.join(logdir, "astats.log")
|
||||
if os.path.exists(ap):
|
||||
log("Prüfe astats.log auf Audiodaten...")
|
||||
with open(ap, errors="ignore") as f:
|
||||
has_audio = "RMS_level" in f.read()
|
||||
|
||||
log(f"Audioanalyse: {'gefunden' if has_audio else 'nicht vorhanden'}")
|
||||
log(f"Audioanalyse: {'gefunden' if has_audio else 'nicht vorhanden'}")
|
||||
|
||||
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]
|
||||
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]
|
||||
|
||||
target = os.path.join(out, "candidates.json")
|
||||
try:
|
||||
with open(target, "w", encoding="utf-8") as f:
|
||||
json.dump(cands, f, ensure_ascii=False, indent=2)
|
||||
log(f"{len(cands)} Kandidaten gespeichert → {target}")
|
||||
except Exception as e:
|
||||
log(f"Fehler beim Schreiben von candidates.json: {e}")
|
||||
sys.exit(2)
|
||||
PY
|
||||
target = os.path.join(out, "candidates.json")
|
||||
try:
|
||||
with open(target, "w", encoding="utf-8") as f:
|
||||
json.dump(cands, f, ensure_ascii=False, indent=2)
|
||||
log(f"{len(cands)} Kandidaten gespeichert → {target}")
|
||||
except Exception as e:
|
||||
log(f"Fehler beim Schreiben von candidates.json: {e}")
|
||||
sys.exit(2)
|
||||
PY
|
||||
|
||||
echo "== Done $ID =="
|
||||
echo "== Done $ID =="
|
||||
```
|
||||
|
||||
### Ergebnis
|
||||
|
||||
Reference in New Issue
Block a user