Files
horror/scripts/stream.sh
2026-08-31 11:54:20 +02:00

124 lines
3.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Startet OBS mit einem eigenen Profil und sendet sofort an MediaMTX.
#
# Das Profil legt fest, wohin gesendet wird; die Szene, was gesendet wird.
# Beide liegen neben deiner normalen OBS-Konfiguration und fassen sie nicht an.
set -euo pipefail
cd "$(dirname "$0")/.."
[ -f .env ] || { echo "Keine .env gefunden."; exit 1; }
set -a; . ./.env; set +a
: "${MTX_SENDEPASSWORT:?MTX_SENDEPASSWORT fehlt in der .env}"
# Ohne Argument lokal, sonst der übergebene Host
ZIEL="${1:-127.0.0.1}"
PROFIL="filmabend"
BASIS="$HOME/.config/obs-studio/basic"
P="$BASIS/profiles/$PROFIL"
command -v obs > /dev/null || { echo "OBS ist nicht installiert."; exit 1; }
# Ohne laufenden MediaMTX bricht OBS mit "is offline" ab — das steht dann
# nur im OBS-Log und man sucht lange.
if ! timeout 3 bash -c "</dev/tcp/${ZIEL}/1935" 2>/dev/null; then
echo "Auf $ZIEL:1935 antwortet nichts."
[ "$ZIEL" = "127.0.0.1" ] && echo "Starte MediaMTX mit: make mtx"
exit 1
fi
mkdir -p "$P" "$BASIS/scenes"
# Sendeziel jedes Mal neu schreiben — es hängt am Argument
cat > "$P/service.json" <<JSON
{
"settings": {
"bwtest": false,
"key": "filmabend?user=sender&pass=$MTX_SENDEPASSWORT",
"server": "rtmp://$ZIEL:1935/",
"use_auth": false
},
"type": "rtmp_custom"
}
JSON
# Einstellungen nur anlegen, nicht überschreiben — du willst Bitrate und
# Auflösung vielleicht anpassen
if [ ! -f "$P/basic.ini" ]; then
cat > "$P/basic.ini" <<'INI'
[General]
Name=filmabend
[Video]
BaseCX=1920
BaseCY=1080
OutputCX=1920
OutputCY=1080
FPSType=0
FPSCommon=30
[Output]
Mode=Simple
[SimpleOutput]
VBitrate=6000
ABitrate=160
StreamEncoder=x264
Preset=veryfast
[Audio]
SampleRate=48000
ChannelSetup=Stereo
INI
fi
# Szene ebenfalls nur beim ersten Mal. Die PipeWire-Quelle fragt beim Start,
# welches Fenster du senden willst.
if [ ! -f "$BASIS/scenes/$PROFIL.json" ]; then
cat > "$BASIS/scenes/$PROFIL.json" <<'JSON'
{
"current_scene": "Filmabend",
"current_program_scene": "Filmabend",
"name": "filmabend",
"scene_order": [{"name": "Filmabend"}],
"sources": [
{
"id": "pipewire-window-capture-source",
"name": "Fenster",
"settings": {"cursor": false},
"versioned_id": "pipewire-window-capture-source"
},
{
"id": "pulse_output_capture",
"name": "Ton",
"settings": {},
"versioned_id": "pulse_output_capture"
},
{
"id": "scene",
"name": "Filmabend",
"settings": {
"items": [
{"name": "Fenster", "visible": true, "pos": {"x": 0.0, "y": 0.0},
"scale": {"x": 1.0, "y": 1.0}, "align": 5, "bounds_type": 2,
"bounds": {"x": 1920.0, "y": 1080.0}},
{"name": "Ton", "visible": true}
]
},
"versioned_id": "scene"
}
]
}
JSON
fi
echo "Sende an rtmp://$ZIEL:1935/filmabend"
echo "OBS fragt gleich, welches Fenster übertragen werden soll."
echo "Beenden: OBS-Fenster schließen oder 'make stream-stop'."
# Ohne --minimize-to-tray bleibt das Fenster sichtbar und lässt sich normal
# schließen. Mit Tray-Symbol ignoriert OBS auch Strg-C im Terminal.
exec obs --profile "$PROFIL" --collection "$PROFIL" \
--startstreaming --disable-updater