# mpv for testing video quality, dont scale.
mpvt() {
mpv --video-unscaled "$@";
- }
+}
# mpv all media files in . or $1
mpvm() {
}
# 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
}
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
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
-l)
volume=1
;;
- -r)
+ -m)
+ mvv=true
+ ;;
+ -s)
case $2 in
tall)
fullscreen=false
# 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
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.
# 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:
# 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
-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
### 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.
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
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
-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.
##### 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 ;;
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
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
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.
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