X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=ffs;h=9efc9f0ebc75e454a076cd01bfa047200632b027;hb=8de1e14e35d0ad62620a59f6e2ca4ba19ddcda3c;hp=d6dc01ff07018546a282f57a782bd52aa6168ccb;hpb=e801d1a57f0b30c57c6f644ab06a0f790159b236;p=distro-setup diff --git a/ffs b/ffs index d6dc01f..9efc9f0 100755 --- a/ffs +++ b/ffs @@ -22,12 +22,9 @@ # ffs = ffmpeg stream -# todo: learn to start working in one corner of the screen. - -# potential improvement: it might be nice that we could have a tall terminal bug only use +# potential improvement: it might be nice that we could have a tall terminal but only use # 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 -# if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi @@ -37,12 +34,16 @@ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" exit status: $?, PIPESTATUS: ${P usage() { cat <&2 + exit 1 + ;; + esac + ffp_args+=($1) +fi if $delay; then # 2500 gets us around a 4 second delay, up from 1.5s. @@ -122,7 +143,7 @@ fi ##### end command line parsing ######## -host=live.iankelling.org:8000 +host=live.iankelling.org:443 if ip n show 10.2.0.1 | grep . &>/dev/null && \ [[ $(dig +timeout=1 +short @10.2.0.1 -x 10.2.0.2 2>&1 ||:) == kd.b8.nz. ]]; then host=127.0.0.1:8000 @@ -155,7 +176,14 @@ else stream_res=$primary_res fi -framerate=8 +# for 1080p, default 256k is poor quality. 500 is ok. 1500 is a bit +# better, so go with that. Also, that is about 2x what is recommended +# in https://livekit.io/webrtc/bitrate-guide (our framerate is lower). + +bitrate=$(( ( ${stream_res/x/*} ) / 1380 )) + +# 8 seems fine. be conservative by going a bit higher. +framerate=10 keyframe_interval=$((framerate * 2)) # Monitor of default sink. @@ -219,14 +247,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 @@ -245,8 +270,7 @@ opts=( -vcodec libvpx -g $keyframe_interval -quality realtime - # for 1080p, default 256k is poor quality. 500 is ok. 1500 is a bit better. - -b:v 1500k + -b:v ${bitrate}k -threads 2 -error-resilient 1 @@ -264,8 +288,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 @@ -324,7 +349,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