#!/usr/bin/env bash # Fan-out: read pre-encoded FLV from pipe → RTMP sinks (stream copy, no re-encode). set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" # shellcheck disable=SC1091 source "${ROOT}/lib/common.sh" # shellcheck disable=SC1091 source "${ROOT}/lib/outputs.sh" require_cmd "${FFMPEG_BIN}" ensure_storage ensure_pipe TEE_SPEC="$(build_fanout_tee_spec)" LOG_FILE="${STORAGE_DIR}/fanout.log" MAX_RETRIES="${FANOUT_RETRIES:-5}" attempt=0 log "fanout → ${#SINKS[@]} sink(s)" while [[ "${attempt}" -le "${MAX_RETRIES}" ]]; do attempt=$((attempt + 1)) log "fanout attempt ${attempt}/${MAX_RETRIES}" if "${FFMPEG_BIN}" -hide_banner -loglevel info \ -thread_queue_size "${THREAD_QUEUE_SIZE}" \ -i "${PIPE_PATH}" \ -map 0 \ -c copy \ -f tee "${TEE_SPEC}" >> "${LOG_FILE}" 2>&1; then log "fanout finished normally" break fi warn "fanout ffmpeg exited — retrying after pipe flush" sleep 1 done