From 9371dc46082e5162eadc21b22197c4fc6f56c8f7 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Wed, 19 Jun 2024 14:19:47 -0400 Subject: [PATCH] stream improvements --- brc2 | 6 ++- ffs | 144 ++++++++++++++++++++++++++++++++-------------------- i3-sway/gen | 24 +++++++-- myx | 80 ++++++++++++++++++++++------- 4 files changed, 173 insertions(+), 81 deletions(-) diff --git a/brc2 b/brc2 index fe5d60f..b22918a 100644 --- 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 728b77d..a8c270b 100755 --- 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. diff --git a/i3-sway/gen b/i3-sway/gen index fba0a67..9d2e691 100755 --- a/i3-sway/gen +++ b/i3-sway/gen @@ -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 </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 -- 2.30.2