Last active
April 2, 2025 21:10
-
-
Save Cdaprod/f6e4841b06390fef5da9b313689be52c to your computer and use it in GitHub Desktop.
Run `streamctl [start, stop, status, attach]` to stream desktop display over RTSP via ffmpeg & Wayland recorder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Self-install if not already in /usr/local/bin | |
INSTALL_PATH="/usr/local/bin/streamctl" | |
if [[ "$0" != "$INSTALL_PATH" ]]; then | |
echo "[+] Installing streamctl to $INSTALL_PATH..." | |
mkdir -p "$(dirname "$INSTALL_PATH")" | |
cp "$0" "$INSTALL_PATH" 2>/dev/null || cat > "$INSTALL_PATH" | |
chmod +x "$INSTALL_PATH" | |
echo "[+] Installed successfully. Run: streamctl start" | |
exit 0 | |
fi | |
# Actual functionality | |
SESSION="wfstream" | |
YOUTUBE_KEY="abcd-1234-xyz9-wxyz" # <-- replace with your key | |
YOUTUBE_URL="rtmp://a.rtmp.youtube.com/live2/$YOUTUBE_KEY" | |
case "$1" in | |
start) | |
tmux has-session -t "$SESSION" 2>/dev/null | |
if [ $? -ne 0 ]; then | |
echo "Starting desktop stream to YouTube..." | |
tmux new-session -d -s "$SESSION" \ | |
"wf-recorder -o - | ffmpeg -f matroska -i - -c:v libx264 -preset veryfast -b:v 4500k -maxrate 4500k -bufsize 9000k -g 60 -f flv '$YOUTUBE_URL'" | |
else | |
echo "Stream already running." | |
fi | |
;; | |
stop) | |
tmux kill-session -t "$SESSION" | |
echo "Stream stopped." | |
;; | |
status) | |
tmux has-session -t "$SESSION" 2>/dev/null && echo "Stream running." || echo "Stream not running." | |
;; | |
attach) | |
tmux attach -t "$SESSION" | |
;; | |
*) | |
echo "Usage: streamctl {start|stop|status|attach}" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment