-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstream.sh
More file actions
executable file
·73 lines (67 loc) · 3.13 KB
/
Copy pathstream.sh
File metadata and controls
executable file
·73 lines (67 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env bash
# Stream the webcam to the BBS fanout service using settings from .env.
#
# Extra args are forwarded to producer.py and override the defaults below:
# ./stream.sh --source test
# ./stream.sh --cols 120 --rows 50 --fps 20
#
# Required .env keys: BBS_HOST, BBS_PORT, TOKEN
# Optional .env keys: CHANNEL, SOURCE, COLS, ROWS,
# TLS=0 -> plaintext (service must also run without -tls-cert/-tls-key)
# INSECURE=1 -> TLS on, but skip cert verification (for a self-signed cert)
# FLIP=0/1 -> force mirror off/on (default: auto — only --source camera)
# CAPTION_FILE=path -> broadcast that file's last line as a subtitle
# AUDIO=1 -> also stream audio (SyncTERM >= 1.10a callers hear it)
# AUDIO_SOURCE=auto|mic|":<mac device>"|<url/file> AUDIO_RATE=44100 AUDIO_CHANNELS=2
# AUDIO_CODEC=auto|flac|wav AUDIO_CHUNK_MS=80
# AUDIO_OFFSET_MS=0 -> lip-sync trim (positive = audio earlier vs video)
# Set DRYRUN=1 to print the command instead of running it.
set -euo pipefail
cd "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
[[ -f .env ]] || { echo "error: .env not found in $(pwd)" >&2; exit 1; }
# Load .env without clobbering vars already in the environment, so an explicit
# `TLS=0 ./stream.sh` overrides the file. (|| [[ -n "$key" ]] catches a final
# line with no trailing newline.)
while IFS='=' read -r key val || [[ -n "$key" ]]; do
[[ "$key" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]] || continue # skip comments/blanks
# strip a matching pair of surrounding quotes (e.g. CAPTURE="usb audio")
# (use #?/%? rather than slice :1:-1 — the latter isn't in bash 3.2 on macOS)
if [[ "$val" == \"*\" || "$val" == \'*\' ]]; then val="${val#?}"; val="${val%?}"; fi
[[ -n "${!key+x}" ]] || export "$key=$val"
done < .env
: "${BBS_HOST:?set BBS_HOST in .env}"
: "${BBS_PORT:?set BBS_PORT in .env}"
: "${TOKEN:?set TOKEN in .env}"
PY="./.venv/bin/python"; [[ -x "$PY" ]] || PY="python3"
args=(
producer.py
--host "$BBS_HOST" --port "$BBS_PORT" --token "$TOKEN"
--channel "${CHANNEL:-cam}" --source "${SOURCE:-camera}"
--cols "${COLS:-80}" --rows "${ROWS:-24}"
)
# TLS on by default. INSECURE=1 keeps encryption but skips cert verification.
# For full plaintext set TLS=0 (and start the service without -tls-cert/-tls-key).
if [[ "${TLS:-1}" == "1" ]]; then
args+=(--tls)
[[ "${INSECURE:-0}" == "1" ]] && args+=(--insecure)
fi
case "${FLIP:-}" in
0|false|no|off) args+=(--no-flip) ;;
1|true|yes|on) args+=(--flip) ;;
esac
[[ -n "${CAPTION_FILE:-}" ]] && args+=(--caption-file "$CAPTION_FILE")
if [[ "${AUDIO:-0}" == "1" ]]; then
args+=(--audio)
[[ -n "${AUDIO_SOURCE:-}" ]] && args+=(--audio-source "$AUDIO_SOURCE")
[[ -n "${AUDIO_RATE:-}" ]] && args+=(--audio-rate "$AUDIO_RATE")
[[ -n "${AUDIO_CHANNELS:-}" ]] && args+=(--audio-channels "$AUDIO_CHANNELS")
[[ -n "${AUDIO_CODEC:-}" ]] && args+=(--audio-codec "$AUDIO_CODEC")
[[ -n "${AUDIO_CHUNK_MS:-}" ]] && args+=(--audio-chunk-ms "$AUDIO_CHUNK_MS")
[[ -n "${AUDIO_OFFSET_MS:-}" ]] && args+=(--audio-offset-ms "$AUDIO_OFFSET_MS")
fi
args+=("$@")
if [[ "${DRYRUN:-0}" == "1" ]]; then
printf '%q ' "$PY" "${args[@]}"; echo
exit 0
fi
exec "$PY" "${args[@]}"