55 lines
1.5 KiB
Bash
55 lines
1.5 KiB
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
# Watch a live recording until its downloaders exit, and record HOW they ended.
|
||
|
|
#
|
||
|
|
# The question this answers: when the stream stops, does ffmpeg finish cleanly
|
||
|
|
# on #EXT-X-ENDLIST, or does it hang until something kills it? Unattended
|
||
|
|
# recording depends on the answer -- a job that never exits needs a hard cap.
|
||
|
|
set -u
|
||
|
|
cd "$(dirname "$0")"
|
||
|
|
LOG=logs/endwatch.log
|
||
|
|
mkdir -p logs
|
||
|
|
|
||
|
|
say() { echo "[$(date '+%H:%M:%S')] $*" | tee -a "$LOG"; }
|
||
|
|
|
||
|
|
say "endwatch start"
|
||
|
|
LAST_TOTAL=0
|
||
|
|
STALL=0
|
||
|
|
|
||
|
|
while true; do
|
||
|
|
N=$(tasklist //FI "IMAGENAME eq ffmpeg.exe" 2>/dev/null | grep -c ffmpeg.exe)
|
||
|
|
TOTAL=0
|
||
|
|
for f in recordings/*; do
|
||
|
|
[ -f "$f" ] && TOTAL=$(( TOTAL + $(stat -c%s "$f") ))
|
||
|
|
done
|
||
|
|
MB=$(( TOTAL / 1048576 ))
|
||
|
|
GROW=$(( (TOTAL - LAST_TOTAL) / 1024 ))
|
||
|
|
|
||
|
|
if [ "$TOTAL" -eq "$LAST_TOTAL" ]; then
|
||
|
|
STALL=$(( STALL + 1 ))
|
||
|
|
else
|
||
|
|
STALL=0
|
||
|
|
fi
|
||
|
|
LAST_TOTAL=$TOTAL
|
||
|
|
|
||
|
|
say "ffmpeg=$N total=${MB}MB grew=${GROW}KB stalled_ticks=$STALL"
|
||
|
|
|
||
|
|
if [ "$N" -eq 0 ]; then
|
||
|
|
say "ALL DOWNLOADERS EXITED -- stream ended and ffmpeg finished on its own"
|
||
|
|
break
|
||
|
|
fi
|
||
|
|
if [ "$STALL" -ge 10 ]; then
|
||
|
|
say "STALLED: files not growing for ~5min but ffmpeg still alive"
|
||
|
|
say " -> it does NOT self-terminate cleanly; unattended runs need a hard cap"
|
||
|
|
break
|
||
|
|
fi
|
||
|
|
sleep 30
|
||
|
|
done
|
||
|
|
|
||
|
|
say "final state:"
|
||
|
|
for f in recordings/*; do
|
||
|
|
[ -f "$f" ] || continue
|
||
|
|
D=$(ffprobe -v error -show_entries format=duration -of csv=p=0 "$f" 2>/dev/null)
|
||
|
|
say " $(basename "$f") $(( $(stat -c%s "$f") / 1048576 ))MB duration=${D:-unknown}s"
|
||
|
|
done
|
||
|
|
say "endwatch done"
|