Something went wrong. Try again.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546#!/bin/bash# laugh.town 24/7 loop. Shuffles the encoded library into a playlist (with the# branded card between films), streams it to stream.place as ONE continuous# RTMPS session via the concat demuxer with -c copy (no transcoding), and# starts over with a fresh shuffle when the cycle ends. Reconnects with# backoff if the connection drops.set -uexport PATH="/opt/homebrew/bin:/usr/local/bin:$PATH" # launchd has a bare PATHcd "$(dirname "$0")/.."mkdir -p logs
KEYFILE="${LAUGHTOWN_KEYFILE:-$HOME/laughtown/.streamkey}"if [[ ! -s $KEYFILE ]]; then echo "No stream key at $KEYFILE. Put the stream.place key there (one line)." >&2 exit 1fiKEY=$(tr -d '[:space:]' < "$KEYFILE")URL="rtmps://stream.place:1935/live/$KEY"
make_playlist() { local pl="logs/playlist.txt" : > "$pl" find encoded -name '*.mp4' -print0 | sort -zR | while IFS= read -r -d '' f; do [[ -f _card.mp4 ]] && printf "file '%s'\n" "$PWD/_card.mp4" >> "$pl" printf "file '%s'\n" "$PWD/$f" >> "$pl" done echo "$pl"}
backoff=5while true; do pl=$(make_playlist) n=$(grep -c "^file" "$pl" || true) echo "$(date '+%F %T') starting cycle: $n entries" >> logs/stream.log start=$(date +%s) ffmpeg -hide_banner -loglevel warning -re \ -fflags +genpts -f concat -safe 0 -i "$pl" \ -c copy -f flv "$URL" >> logs/stream.log 2>&1 ran=$(( $(date +%s) - start )) # If we streamed for a while, the exit was end-of-cycle or a late drop: # reshuffle and reconnect immediately. Rapid failures back off up to 5 min. if (( ran > 60 )); then backoff=5; else backoff=$(( backoff * 2 )); (( backoff > 300 )) && backoff=300; fi echo "$(date '+%F %T') ffmpeg exited after ${ran}s; restarting in ${backoff}s" >> logs/stream.log sleep "$backoff"done