mainly minor fixes
[distro-setup] / ffs
diff --git a/ffs b/ffs
index 0bb4ae7b94781a6c2792a078b91d58a0f227fc23..fe42908750b636051efe1ba9d2393b89d95f94e3 100755 (executable)
--- a/ffs
+++ b/ffs
 # the top half for a 1080p stream, this is how:
 # https://superuser.com/questions/1106674/how-to-add-blank-lines-above-the-bottom-in-terminal
 #
-# potential improvement: sometimes I probably want to stream full height
-# window. I could add an option for that.
-
-# potential improvement: setup a function which automatically mutes after some time, or
-# after some time of no audio input.
-
-
-### begin background/development docs ###
-
-# zmq vs stdin commands:
-#
-# * zmq allows targeting a specific filter when there are duplicates.
-#
-# * if you type stdin command too slow, ffmpeg will die because it stops
-#   doing normal work while it is waiting.
-#
-# * zmq returns a result to the calling process, rather than printing to
-#   stdout.
-#
-# * the only simple zmq tool I found, zmqsend, requires compiling. I
-#   used the latest ffmpeg 7.0.1. Build like so:
-#
-# p build-dep ffmpeg/aramo
-# ./configure --enable-libzmq # i already had libzmq3-dev installed
-# make alltools
-# cp tools/zmqsend /a/opt/bin
-#
-# * ffmpeg debug output was useful in testing zmq commands.
-#
-# * Important documentation for stdin commands is only found by typing
-#   "c" into the stdin of ffmpeg and reading the output.
-#
-#
-#
-# stdin command docs, before I abandoned it for zmq:
-#  mkfifo -m 0600 /tmp/iank-ffmpeg
-# # ffmpeg sits and waits until we do this. dunno why.
-#  echo >/tmp/iank-ffmpeg &
-#  ffmpeg ... </tmp/iank-ffmpeg |& while read -r line; do : check results; done
-#  # example of working commands:
-#  echo "cdrawbox -1 t 0" >/tmp/iank-ffmpeg
-#  echo "cdrawbox -1 t fill" >/tmp/iank-ffmpeg
-#  echo "cdrawtext -1 reinit text=''" >/tmp/iank-ffmpeg
-#  echo "cvolume -1 volume=1" >/tmp/iank-ffmpeg
-
-
-# For testing: to show the number of audio channels in a resulting file
-# https://stackoverflow.com/questions/47905083/how-to-check-number-of-channels-in-my-audio-wav-file-using-ffmpeg-command
-#
-# ffprobe -i /tmp/out.wav -show_entries stream=channels -select_streams a:0 -of compact=p=0:nk=1 -v 0
-
-# for a right/left speaker test:
-# https://askubuntu.com/questions/148363/which-linux-command-can-i-use-to-test-my-speakers-for-current-talk-radio-output
-# p install alsa-utils
-# speaker-test -t wav -c 2 -l 1
-
-# There are 2 other options for audio, so I wanted to do a little
-# performance measurement of this method.
-# 1 is to combine the 2 audio sources in pulse,
-# https://unix.stackexchange.com/questions/351764/create-combined-source-in-pulseaudio .
-# 1 is to record mumble and combine in post processing.
-
-### benchmark / perf tests: these are pretty inaccurate.
-# 29 seconds cpu use. video bitrate 1500k, 8 fps, 2x keyframe interval.
-# * 64k vorbis: 69.7%
-# * 128k vorbis: 70.1% (used in subsequent tests)
-# * 1 audio input: 64.3%
-# * 0 audio inputs: 59.2%
-
-# how I did perf testing: add -to 00:00:30 to ffmpeg opts to
-# conveniently exit after measurement. Then run:
-#
-# ffmpeg "${opts[@]}" &
-# pid=$!
-# sleep 29
-# ps -p $pid -o %cpu
-# kill %%
-
-# filter for only 1 audio input:
-#-filter_complex "[0]azmq,volume=precision=fixed;[1]zmq='b=tcp\://127.0.0.1\:5557',drawbox=color=0x262626,drawtext=fontsize=90: fontcolor=beige: x=40: y=40: text=''"
-# filter with 0 audio input:
-# -filter_complex "[0]zmq='b=tcp\://127.0.0.1\:5557',drawbox=color=0x262626,drawtext=fontsize=90: fontcolor=beige: x=40: y=40: text=''"
-
-
-# When things weren't working, I did some checking on newer ffmpeg to
-# see if that helped. It never did. I compiled the latest ffmpeg release
-# tarball, 7.0.1, and tried the version in debian bullseye by schrooting
-# before running ffmpeg. Building was just configure; make, but then I
-# found some flags that were needed. gpl flags r just because I noticed them.
-# ./configure --enable-libzmq --enable-libpulse --enable-libvorbis --enable-gpl --enable-version3
-#
-
-### end background/development docs ###
 
 
 if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi
@@ -130,12 +37,16 @@ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" exit status: $?, PIPESTATUS: ${P
 
 usage() {
   cat <<EOF
-Usage: ${0##*/} [OPTIONS] [sysops|tech|staff]
-3 mountpoints: fsf-sysops (default, public), fsf (all staff), fsf-tech (tech team)
+Usage: ${0##*/} [OPTIONS] [sysops|tech|staff|test]
+
+arg is icecast mountpoint suffix, except staff removes suffix.
 
 -d    debug.
--f    Stream full screen even high resolution.
--t    Stream tall half screen
+-r RESOLUTION_TYPE
+   full: full screen even high resolution.
+   tall (default): half screen.
+   quarter: self evident
+-l   loud/listen. Start unmuted. Usually for testing.
 -u    Undelayed. Removes 5 second video delay, and about 4 second audio delay.
 -w    do not launch watch of stream
 
@@ -161,9 +72,10 @@ debug=false
 delay=true
 loglevel=fatal
 watch=true
+volume=0
 fullscreen=false
-tall=false
-temp=$(getopt -l help hdftuw "$@") || usage 1
+tall=true
+temp=$(getopt -l help hdlr:uw "$@") || usage 1
 eval set -- "$temp"
 while true; do
   case $1 in
@@ -173,13 +85,25 @@ while true; do
       loglevel=info
       ffp_args+=(-d)
       ;;
-    -f)
-      fullscreen=true
-      tall=false
+    -l)
+      volume=1
       ;;
-    -t)
-      fullscreen=false
-      tall=true
+    -r)
+      case $2 in
+        tall)
+          fullscreen=false
+          tall=true
+          ;;
+        quarter)
+          fullscreen=false
+          tall=false
+          ;;
+        full)
+          fullscreen=true
+          tall=false
+          ;;
+      esac
+      shift
       ;;
     -w)
       watch=false
@@ -195,17 +119,24 @@ while true; do
 done
 
 mount_suffix=-sysops
-case $1 in
-  sysops|tech)
-    mount_suffix=-$1
-    ;;&
-  tech)
-    delay=false
-    ;;
-  staff)
-    mount_suffix=
-    ;;
-esac
+if [[ $1 ]]; then
+  case $1 in
+    sysops|tech)
+      mount_suffix=-$1
+      ;;&
+    tech)
+      delay=false
+      ;;
+    staff)
+      mount_suffix=
+      ;;
+    *)
+      echo "error: unexpected \$1: $1" >&2
+      exit 1
+      ;;
+  esac
+  ffp_args+=($1)
+fi
 
 if $delay; then
   # 2500 gets us around a 4 second delay, up from 1.5s.
@@ -312,14 +243,11 @@ opts=(
   #
   # man page say zmq url default includes "localhost", but specifying a
   # localhost url caused an error for me.
-  -filter_complex "[0]azmq,volume=precision=fixed: volume=0 [vol0];
+  -filter_complex "[0]azmq,volume=precision=fixed: volume=$volume [vol0];
 [1]azmq='b=tcp\://127.0.0.1\:5556',volume=precision=fixed: volume=0 [vol1];
 [vol0][vol1] amerge=inputs=2;
 [2]zmq='b=tcp\://127.0.0.1\:5557',drawbox=color=0x262626,drawtext=fontsize=90: fontcolor=beige: x=40: y=40: text=''${delay_arg}[out]"
 
-#  [vol0][vol1] amerge=inputs=2,adelay=6000:all=1;
-
-
   # An online source says to match a 5 second vid delay, we can do an
   # audio delay filter: "adelay=5000|5000". However, we already get
   # a stream delay of about 2 seconds, and having the audio be about
@@ -357,8 +285,9 @@ opts=(
 
 rm -f /tmp/iank-ffmpeg-interlude-toggle
 
-# start muted
-pactl set-source-mute @DEFAULT_SOURCE@ true
+# system mute. disabled, just using application level mute atm.
+#
+# pactl set-source-mute @DEFAULT_SOURCE@ true
 
 if pkill -f ^ffmpeg.\*icecast://source.\*/fsf; then
   sleep 1
@@ -417,7 +346,7 @@ if [[ $mount_suffix == -sysops ]]; then
   touch $HOME/.iank-stream-on
 fi
 
-echo true >$HOME/.iank-stream-muted
+echo $volume >$HOME/.iank-stream-muted
 
 ffmpeg "${opts[@]}" &
 if $watch; then
@@ -427,3 +356,92 @@ if $watch; then
   kill %%
   rm -f $HOME/.iank-stream-on
 fi
+
+
+
+### begin background/development docs ###
+
+# zmq vs stdin commands:
+#
+# * zmq allows targeting a specific filter when there are duplicates.
+#
+# * if you type stdin command too slow, ffmpeg will die because it stops
+#   doing normal work while it is waiting.
+#
+# * zmq returns a result to the calling process, rather than printing to
+#   stdout.
+#
+# * the only simple zmq tool I found, zmqsend, requires compiling. I
+#   used the latest ffmpeg 7.0.1. Build like so:
+#
+# p build-dep ffmpeg/aramo
+# ./configure --enable-libzmq # i already had libzmq3-dev installed
+# make alltools
+# cp tools/zmqsend /a/opt/bin
+#
+# * ffmpeg debug output was useful in testing zmq commands.
+#
+# * Important documentation for stdin commands is only found by typing
+#   "c" into the stdin of ffmpeg and reading the output.
+#
+#
+#
+# stdin command docs, before I abandoned it for zmq:
+#  mkfifo -m 0600 /tmp/iank-ffmpeg
+# # ffmpeg sits and waits until we do this. dunno why.
+#  echo >/tmp/iank-ffmpeg &
+#  ffmpeg ... </tmp/iank-ffmpeg |& while read -r line; do : check results; done
+#  # example of working commands:
+#  echo "cdrawbox -1 t 0" >/tmp/iank-ffmpeg
+#  echo "cdrawbox -1 t fill" >/tmp/iank-ffmpeg
+#  echo "cdrawtext -1 reinit text=''" >/tmp/iank-ffmpeg
+#  echo "cvolume -1 volume=1" >/tmp/iank-ffmpeg
+
+
+# For testing: to show the number of audio channels in a resulting file
+# https://stackoverflow.com/questions/47905083/how-to-check-number-of-channels-in-my-audio-wav-file-using-ffmpeg-command
+#
+# ffprobe -i /tmp/out.wav -show_entries stream=channels -select_streams a:0 -of compact=p=0:nk=1 -v 0
+
+# for a right/left speaker test:
+# https://askubuntu.com/questions/148363/which-linux-command-can-i-use-to-test-my-speakers-for-current-talk-radio-output
+# p install alsa-utils
+# speaker-test -t wav -c 2 -l 1
+
+# There are 2 other options for audio, so I wanted to do a little
+# performance measurement of this method.
+# 1 is to combine the 2 audio sources in pulse,
+# https://unix.stackexchange.com/questions/351764/create-combined-source-in-pulseaudio .
+# 1 is to record mumble and combine in post processing.
+
+### benchmark / perf tests: these are pretty inaccurate.
+# 29 seconds cpu use. video bitrate 1500k, 8 fps, 2x keyframe interval.
+# * 64k vorbis: 69.7%
+# * 128k vorbis: 70.1% (used in subsequent tests)
+# * 1 audio input: 64.3%
+# * 0 audio inputs: 59.2%
+
+# how I did perf testing: add -to 00:00:30 to ffmpeg opts to
+# conveniently exit after measurement. Then run:
+#
+# ffmpeg "${opts[@]}" &
+# pid=$!
+# sleep 29
+# ps -p $pid -o %cpu
+# kill %%
+
+# filter for only 1 audio input:
+#-filter_complex "[0]azmq,volume=precision=fixed;[1]zmq='b=tcp\://127.0.0.1\:5557',drawbox=color=0x262626,drawtext=fontsize=90: fontcolor=beige: x=40: y=40: text=''"
+# filter with 0 audio input:
+# -filter_complex "[0]zmq='b=tcp\://127.0.0.1\:5557',drawbox=color=0x262626,drawtext=fontsize=90: fontcolor=beige: x=40: y=40: text=''"
+
+
+# When things weren't working, I did some checking on newer ffmpeg to
+# see if that helped. It never did. I compiled the latest ffmpeg release
+# tarball, 7.0.1, and tried the version in debian bullseye by schrooting
+# before running ffmpeg. Building was just configure; make, but then I
+# found some flags that were needed. gpl flags r just because I noticed them.
+# ./configure --enable-libzmq --enable-libpulse --enable-libvorbis --enable-gpl --enable-version3
+#
+
+### end background/development docs ###