stream improvements
authorIan Kelling <ian@iankelling.org>
Wed, 19 Jun 2024 18:19:47 +0000 (14:19 -0400)
committerIan Kelling <ian@iankelling.org>
Wed, 19 Jun 2024 18:33:00 +0000 (14:33 -0400)
brc2
ffs
i3-sway/gen
myx

diff --git a/brc2 b/brc2
index fe5d60fce42c9a8fb1a7b567ed0a2bce0517f77e..b22918abf8372d693440a1dc4125dbabd082e9dc 100644 (file)
--- a/brc2
+++ b/brc2
@@ -3294,7 +3294,7 @@ mpva() {
 # mpv for testing video quality, dont scale.
 mpvt() {
   mpv --video-unscaled "$@";
-  }
+}
 
 # mpv all media files in . or $1
 mpvm() {
@@ -4852,7 +4852,9 @@ EOF
 }
 # icecast rm -r
 icrmr() {
-  find /var/icecast -type f -delete
+  if [[ -d /var/icecast ]]; then
+    find /var/icecast -type f -delete
+  fi
   ssh li.b8.nz find /var/icecast -type f -delete
 }
 
diff --git a/ffs b/ffs
index 728b77d4e67288235f7ba96a3dc60f6245269f4c..a8c270b0c90720f4df6a4685b21c855292419568 100755 (executable)
--- a/ffs
+++ b/ffs
@@ -39,7 +39,7 @@ Usage: ${0##*/} [OPTIONS] [sysops|tech|staff|test]
 arg is icecast mountpoint suffix, except staff removes suffix.
 
 -d    debug.
--r RESOLUTION_TYPE
+-s SPLIT_TYPE
    full: full screen even high resolution.
    tall (default): half screen.
    quarter: self evident
@@ -72,7 +72,8 @@ watch=true
 volume=0
 fullscreen=false
 tall=true
-temp=$(getopt -l help hdlr:uw "$@") || usage 1
+mvv=false
+temp=$(getopt -l help hdlms:uw "$@") || usage 1
 eval set -- "$temp"
 while true; do
   case $1 in
@@ -85,7 +86,10 @@ while true; do
     -l)
       volume=1
       ;;
-    -r)
+    -m)
+      mvv=true
+      ;;
+    -s)
       case $2 in
         tall)
           fullscreen=false
@@ -215,8 +219,12 @@ else
   # 1000 is a bit blury, 1500 is pretty clear, 2000 makes scrolling
   # adjust much faster, 2500 has marginal improvement on that.
   #
-  # note https://livekit.io/webrtc/bitrate-guide (our framerate is lower)
-  bitrate_1080=2000
+  # note https://livekit.io/webrtc/bitrate-guide
+  if $mvv; then
+    bitrate_1080=1000
+  else
+    bitrate_1080=2000
+  fi
 
   encode_settings=(
     -vcodec libvpx
@@ -228,8 +236,13 @@ fi
 bitrate=$(( ( stream_x * stream_y ) / ( (1920*1080) / bitrate_1080 ) ))
 
 
-# 8 seems fine. be conservative by going a bit higher.
-framerate=10
+if $mvv; then
+  framerate=5
+else
+  # 8 seems fine. be conservative by going a bit higher.
+  framerate=10
+fi
+
 keyframe_interval=$((framerate * 2))
 
 # Monitor of default sink.
@@ -241,48 +254,35 @@ pa_sink=$(pactl get-default-sink).monitor
 # probably only when we are using delayed output
 thread_queue_size_arg="-thread_queue_size 500"
 
-opts=(
-  # global options
-  # be relatively quiet. switch to debug when testing.
-  -v $loglevel
-  -hide_banner
-  -nostats
-
-  ${global_extra_args[@]}
-
-  # tested for decreasing latency: did not help.
-  # -probesize 32
-  # tested for warning "Queue input is backward in time". did not help.
-  #-rtbufsize 500M
-
-  # note: ordering of inputs also affects zmqsend commands.
-
-  ## audio input options
-
-  -f pulse
-  -name ffs
-  # note: duplicated
-  $thread_queue_size_arg
-  -fragment_size 512
-  -i default
-
-  -f pulse
-  $thread_queue_size_arg
-  # pulse knows this name somewhere
-  -name ffsdesktop
-  # This fixes latency. i haven't tried tuning it, but going too low creates
-  # choppy output.
-  -fragment_size 512
-  -i "$pa_sink"
-
-
-  ## video input options
-  -video_size $stream_res
-  $thread_queue_size_arg
-  -f x11grab
-  -framerate $framerate
-  -i :0.0+$x_offset.0
-
+# hardcoded switch for debugging
+doaudio=true
+if $doaudio; then
+  audio_out_args=(
+    -c:a libvorbis
+    -b:a 92k
+    # afaik, this ensures that the amerge doesn't make 4 channel output if
+    # our output format supported it.
+    -ac 2
+  )
+  audio_in_args=(
+
+    -f pulse
+    -name ffs
+    # note: duplicated
+    $thread_queue_size_arg
+    -fragment_size 512
+    -i default
+
+    -f pulse
+    $thread_queue_size_arg
+    # pulse knows this name somewhere
+    -name ffsdesktop
+    # This fixes latency. i haven't tried tuning it, but going too low creates
+    # choppy output.
+    -fragment_size 512
+    -i "$pa_sink"
+  )
+  filter_args=(
   # Video + audio filter. Note: this has only the things we actually need in it.
   #
   # volume=precision=fixed fixes this error:
@@ -313,6 +313,38 @@ opts=(
   # identifier is called an "output pad" in man ffmpeg-filters, and a
   # "link label" in man ffmpeg.
   -map '[out]'
+  )
+fi
+
+opts=(
+  # global options
+  # be relatively quiet. switch to debug when testing.
+  -v $loglevel
+  -hide_banner
+  -nostats
+
+  ${global_extra_args[@]}
+
+  # tested for decreasing latency: did not help.
+  # -probesize 32
+  # tested for warning "Queue input is backward in time". did not help.
+  #-rtbufsize 500M
+
+  # note: ordering of inputs also affects zmqsend commands.
+
+  ${audio_in_args[@]}
+
+  ## video input options
+  -video_size $stream_res
+  $thread_queue_size_arg
+  -f x11grab
+  -framerate $framerate
+  -i :0.0+$x_offset.0
+
+  "${filter_args[@]}"
+
+  ${audio_out_args[@]}
+
 
   # video output options
   -g $keyframe_interval
@@ -320,13 +352,6 @@ opts=(
   -b:v ${bitrate}k
 
 
-  ## audio output options
-  -c:a libvorbis
-  -b:a 128k
-  # afaik, this ensures that the amerge doesn't make 4 channel output if
-  # our output format supported it.
-  -ac 2
-
   -content_type video/webm
   -f webm
   icecast://source:$pass@$host/fsf$mount_suffix.webm
@@ -408,6 +433,13 @@ fi
 
 ### begin background/development docs ###
 
+# 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
+# 2 seconds ahead is fine, they do that intentionally in soccer
+# matches.
+
+
 # zmq vs stdin commands:
 #
 # * zmq allows targeting a specific filter when there are duplicates.
index fba0a674616d7ae4e0e21143f181bab0ae03982a..9d2e69192fcc3321efeeaed6d0113252a47a6393 100755 (executable)
@@ -39,7 +39,25 @@ if [[ $1 == bar ]] || (( monitor_count >= 2 )); then
 fi
 
 move_arg=right
-if xrandr --listmonitors | awk '$2 == "BIG-RIGHT"' |grep . >/dev/null; then
+if xrandr --listmonitors | awk '$2 == "BIG-BOTTOM-LEFT"' |grep . >/dev/null; then
+  cat >>$dir/config <<'EOF'
+# by default, new workspaces are created on whatever screen doesn't have
+# one active or else the current one. That is annoying, I have one
+# primary monitor, I don't want a new workspace created on secondary
+# monitor just because I happen be focused on it. This fixes that.
+workspace 1 output primary
+workspace 2 output BIG-LEFT
+workspace 3 output BIG-BOTTOM-LEFT
+workspace 4 output BIG-RIGHT
+workspace 5 output BIG-RIGHT
+workspace 6 output BIG-RIGHT
+workspace 7 output BIG-RIGHT
+workspace 8 output BIG-RIGHT
+workspace 9 output BIG-RIGHT
+workspace 10 output BIG-RIGHT
+EOF
+  move_arg="BIG-BOTTOM-LEFT BIG-RIGHT primary"
+elif xrandr --listmonitors | awk '$2 == "BIG-LEFT"' |grep . >/dev/null; then
   cat >>$dir/config <<'EOF'
 # by default, new workspaces are created on whatever screen doesn't have
 # one active or else the current one. That is annoying, I have one
@@ -61,10 +79,6 @@ else
   mon2=$(xrandr | awk '$2 == "connected" && $3 != "primary" {print $1}')
   if [[ $mon2 ]]; then
     cat >>$dir/config <<EOF
-# by default, new workspaces are created on whatever screen doesn't have
-# one active or else the current one. That is annoying, I have one
-# primary monitor, I don't want a new workspace created on secondary
-# monitor just because I happen be focused on it. This fixes that.
 workspace 1 output primary
 workspace 2 output $mon2
 workspace 3 output $mon2
diff --git a/myx b/myx
index 89a4da2ccee001c740e4303e244741e8597341e0..b22e9bef62df890cc5aa9603eaf48e527948cbd2 100755 (executable)
--- a/myx
+++ b/myx
@@ -35,10 +35,16 @@ Alters i3 config.
 
 -n  Dry run
 
+-f  No split, full resolution, like the screen would be without any
+    modifications. This happens automatically for small screens.
+
 -r  Restart secondary monitor
 
--s  No stream setup. Normally, split monitor into 2 virtual screens and
-      set max resolution 2560x1440
+-s split type. split monitor into 1 or more virtual screens
+   full: no split, full screen.
+   tall (default): half screen.
+   quarter: left side is 2 quarter screens, right is 1 tall screen
+
 
 
 -h|--help             Print help and exit.
@@ -91,15 +97,38 @@ date "+%A, %B %d, %r, %S seconds"
 ##### begin command line parsing ########
 
 dry_run=false
-stream=true
+downres=true
+quarter=true
+tall=false
 restart=false
-temp=$(getopt -l help nrs "$@") || usage 1
+temp=$(getopt -l help fnrs: "$@") || usage 1
 eval set -- "$temp"
 while true; do
   case $1 in
+    -f)
+      downres=false
+      quarter=false
+      tall=false
+      ;;
     -n) dry_run=true ;;
+    -s)
+      case $2 in
+        tall)
+          tall=true
+          quarter=false
+          ;;
+        quarter)
+          tall=false
+          quarter=true
+          ;;
+        full)
+          tall=false
+          quarter=false
+          ;;
+      esac
+      shift
+      ;;
     -r) restart=true ;;
-    -s) stream=false ;;
     -h|--help) usage 0 ;;
     --) shift; break ;;
     *) echo "$0: Internal error! unexpected args: $*" ; exit 1 ;;
@@ -118,7 +147,7 @@ if $dry_run; then
   m() { printf "$script_name: %s\n" "$*"; }
 fi
 
-for mon_suffix in LEFT RIGHT; do
+for mon_suffix in TOP-LEFT BOTTOM-LEFT LEFT RIGHT; do
   if xrandr --listmonitors | awk '$2 == "BIG-'$mon_suffix\" |grep . >/dev/null; then
     m xrandr --delmonitor BIG-$mon_suffix
   fi
@@ -148,6 +177,7 @@ if [[ $secondary_out ]]; then
   left_right_arg=--right-of
   if [[ $secondary_out == HDMI2 && $(edid card0-HDMI-A-2) == 192efbdcef ]] || \
        [[ $secondary_out == HDMI-1 && $(edid card1-HDMI-A-1 ) == 7c58f9ac1e ]] || \
+       [[ $secondary_out == DP-2 && $(edid card1-DP-2 ) == 0c35564b67 ]] || \
        [[ $secondary_out == DP-1 && $(edid card1-DP-1 ) == f3364bc6c1 ]]; then
     left_right_arg=--left-of
     x_offset=0
@@ -168,21 +198,28 @@ else
   target_y=$primary_y
 fi
 
+if (( target_x <= 1280 )); then
+  quarter=false
+  tall=false
+fi
 
-
-if $stream && (( target_x > 1280 )); then
-
-  if (( target_x > 2560 )); then
-    target_x=2560
-    target_y=1440
-    target_res=${target_x}x$target_y
-  fi
-
+if $downres && (( target_x > 2560 )); then
+  target_x=2560
+  target_y=1440
+  target_res=${target_x}x$target_y
   if [[ $secondary_out || $primary_res != "$target_res" ]]; then
     m xrandr --output $target_out $left_right_arg --mode $target_res
   fi
+else
+  m xrandr --output $target_out $left_right_arg --mode $target_res
+fi
+
+
+half_x=$(( target_x / 2 ))
+half_y=$(( target_y / 2 ))
+
+if $tall; then
 
-  half_x=$(( target_x / 2 ))
   # 298 & 336 are millimeters. I took them from a monitor I was using. I
   # don't know if they are important, I assume not important enough to
   # change for different monitors.
@@ -191,9 +228,16 @@ if $stream && (( target_x > 1280 )); then
 
   move-ws BIG-LEFT 2
   move-ws BIG-RIGHT 3 4 5 6 7 8 9 10
+elif $quarter; then
 
-else
-  m xrandr --output $target_out $left_right_arg --mode $target_res
+  m xrandr --setmonitor BIG-LEFT $half_x/298x$half_y/336+$x_offset+0 $target_out
+  m xrandr --setmonitor BIG-BOTTOM-LEFT $half_x/298x$half_y/336+$x_offset+$half_y none
+  m xrandr --setmonitor BIG-RIGHT $half_x/298x$target_y/336+$(( x_offset + half_x ))+0 none
+
+  move-ws BIG-LEFT 2
+  move-ws BIG-BOTTOM-LEFT 3
+  move-ws BIG-RIGHT 4 5 6 7 8 9 10
+else # fullscreen
   move-ws $target_out 2 3 5 6 7 8 9 10
 fi