Comments and formatting
[streamdesktop.git] / streamdesktop
index f963025e373383d4ed2cffaa3de3036ca7885845..925a4da30890908f48e328ffd115f87da747f806 100755 (executable)
@@ -30,22 +30,23 @@ fi
 
 # Server side dependencies: icecast2
 
-
-DATE=$(date +%Y-%m-%d-%H_%M_%S)
-PASSWORD=hackme
+# Server connection settings
 SERVER=my.icecast2server.org
-PORT=80
-MOUNT=$1
-[ "$MOUNT" = "" ] && MOUNT=recording
-BITRATE=1000000
-SOUNDQUALITY=0.4
-FRAMERATE=20
-SHOWPOINTER="true"
+PORT=80 # port to stream to
+PASSWORD=hackme
+
+# Stream settings
+BITRATE=1000000 # Bitrate of the video, in bps
+SOUNDQUALITY=0.4 # OGG compression quality, from 0 to 1
+FRAMERATE=20 # frames per second
+SHOWPOINTER="true" # show or hide the mouse pointer
 # Width and height are upper limits. Video will not be upscaled or stretched, it would be proportionally downscaled to fit the WIDTH and HEIGHT dimensions
 WIDTH=1280
 HEIGHT=720
 
-WINDOWLIST="$(wmctrl -l)"
+DATE=$(date +%Y-%m-%d-%H_%M_%S)
+MOUNT=$1
+[ "$MOUNT" = "" ] && MOUNT=recording
 
 cat << EOF
 Usage: $0 [title]
@@ -56,18 +57,20 @@ The title parameter will be used for the name of the mount, and the name of the
 
 AUDIO INPUT: this script will record and stream the audio from the default input selection in Pulseaudio. Click on the volume icon in your desktop environment, go to settings, then input, and select the appropriate device and input level.
 
-SCREEN SELECTION. Note: broadcasting a single window may crash if you minimize or resize the screen after the streaming starts! If you have issues with this, select 0 to broadcast the full screen, but remember to close or hide any privacy-sensitive windows."
+SCREEN SELECTION. Note: broadcasting a single window may crash if you minimize or resize the screen after the streaming starts! If you have issues with this, select 0 to broadcast the full screen, but remember to close or hide any privacy-sensitive windows." If the stream is just an empty black square, make sure your desktop is running X11, not Wayland or others. 
 
 0: Capture FULL SCREEN
 EOF
 
+# Window selector
+WINDOWLIST="$(wmctrl -l)"
 i=1
 echo "$WINDOWLIST" |while read line
 do
-       echo -n "$i: "
-       name=$(echo $line| cut -d' ' -f 4-)
-       echo $name
-       i=$(expr $i + 1)
+  echo -n "$i: "
+  name=$(echo $line| cut -d' ' -f 4-)
+  echo $name
+  i=$(expr $i + 1)
 done
 
 echo
@@ -77,11 +80,13 @@ read -s -n1 SELECTION
 XID=$(echo "$WINDOWLIST" | sed -n "${SELECTION}p" | sed 's/ .*//')
 
 if [ "$SELECTION" = 0 ] || [ "$SELECTION" = "" ] ; then
-       XPARAM=""
+  XPARAM=""
 else
-       XPARAM="xid=$XID"
+  XPARAM="xid=$XID"
 fi
 
+
+# The video needs to be processed after recording
 trap ctrl_c INT
 ctrl_c() {
   echo
@@ -96,11 +101,13 @@ ctrl_c() {
   echo   ffmpeg -i $MOUNT-${DATE}.webm -acodec copy -vcodec copy -ss 00:19:27 -to 02:18:51 trimmed.webm
 }
 
+
 echo STARTING STREAM in 2 seconds. Press CTRL+C to end the session.
 sleep 2
 echo Streaming at http://$SERVER/recording.webm
 echo
 
+# GSTREAMER 1.0 pipeline for capture, save to file, and stream to icecast2
 gst-launch-1.0 --eos-on-shutdown ximagesrc use-damage=false $XPARAM show-pointer=$SHOWPOINTER \
 ! videorate ! video/x-raw,framerate=$FRAMERATE/1 \
 ! videoscale ! video/x-raw, width=$WIDTH, height=$HEIGHT \