2023-11-01 07:20:12 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
cd "$(dirname "$(realpath "$BASH_SOURCE")")"
|
2023-11-08 10:44:33 +00:00
|
|
|
sys_python="python3"
|
|
|
|
function setUser() {
|
|
|
|
export fstream_arg_user="user"
|
|
|
|
export fstream_arg_user_password="123"
|
|
|
|
}
|
|
|
|
function setChannel() {
|
|
|
|
export fstream_arg_channel="default"
|
|
|
|
export fstream_arg_channel_password="456"
|
2023-11-01 07:20:12 +00:00
|
|
|
}
|
2022-11-01 19:53:08 +00:00
|
|
|
|
2023-11-08 10:44:33 +00:00
|
|
|
export fstream_arg_bufsize="4096"
|
|
|
|
aes_password="789"
|
2022-11-01 19:53:08 +00:00
|
|
|
|
2023-11-08 10:44:33 +00:00
|
|
|
enc_resolution="480"
|
|
|
|
enc_framerate="15"
|
|
|
|
enc_bitrate="1M"
|
|
|
|
enc_preset="ultrafast"
|
2022-11-01 19:53:08 +00:00
|
|
|
|
2023-11-08 10:44:33 +00:00
|
|
|
enc_cmd=(
|
2023-11-01 07:20:12 +00:00
|
|
|
ffmpeg
|
2022-11-01 19:53:08 +00:00
|
|
|
|
2023-11-01 07:20:12 +00:00
|
|
|
# INPUT
|
|
|
|
-strict experimental -avioflags direct -thread_queue_size 1 -hwaccel auto -probesize 32 -fflags nobuffer -flags low_delay -flags2 fast # delay hack
|
2023-11-08 10:44:33 +00:00
|
|
|
-f x11grab -framerate "$enc_framerate" -i "$DISPLAY" # linux
|
|
|
|
#-f gdigrab -framerate "$enc_framerate" -i desktop # windows
|
|
|
|
-vf "scale=-2:$enc_resolution"
|
2022-11-01 19:53:08 +00:00
|
|
|
|
2023-11-01 07:20:12 +00:00
|
|
|
# ENCODING
|
|
|
|
-max_probe_packets 0 -max_delay 0 -flags2 fast # delay hack
|
2023-11-08 10:44:33 +00:00
|
|
|
-c:v libx264 -pix_fmt yuv420p -preset "$enc_preset" -tune zerolatency -x264-params "nal-hrd=cbr" -b:v "$enc_bitrate" -minrate "$enc_bitrate" -maxrate "$enc_bitrate" -bufsize "${enc_bitrate}*2"
|
2023-11-01 07:20:12 +00:00
|
|
|
-x264opts intra-refresh=1 # delay hack
|
2022-11-01 19:53:08 +00:00
|
|
|
|
2023-11-01 07:20:12 +00:00
|
|
|
# OUTPUT
|
|
|
|
-flags2 fast # delay hack
|
|
|
|
-f mpegts
|
|
|
|
-flags2 fast -muxdelay 0 -muxpreload 0 -max_delay 0 -flush_packets 1 # delay hack
|
|
|
|
-
|
|
|
|
)
|
2022-11-01 19:53:08 +00:00
|
|
|
|
2023-11-08 10:44:33 +00:00
|
|
|
if [ "$fstream_arg_bufsize" == "" ] || [ "$fstream_arg_bufsize" == "0" ]; then
|
|
|
|
unset fstream_arg_bufsize
|
2023-11-01 07:20:12 +00:00
|
|
|
fi
|
|
|
|
|
2023-11-08 10:44:33 +00:00
|
|
|
export fstream_arg_token=""
|
|
|
|
setChannel
|
|
|
|
while :; do
|
|
|
|
# Get token
|
|
|
|
export fstream_ssl="1"
|
|
|
|
export fstream_ssl_ignoreCert="1"
|
|
|
|
setUser
|
|
|
|
unset fstream_arg_token
|
|
|
|
unset fstream_arg_channel
|
|
|
|
unset fstream_arg_channel_password
|
|
|
|
export fstream_arg_token="$("$sys_python" fstream.py "fier.me:61921" token)"
|
|
|
|
unset fstream_arg_user_password
|
|
|
|
|
|
|
|
# Broadcast
|
|
|
|
unset fstream_ssl
|
|
|
|
unset fstream_ssl_ignoreCert
|
|
|
|
setChannel
|
|
|
|
|
|
|
|
if ! [ "$fstream_aespass" == "" ]; then
|
|
|
|
"${enc_cmd[@]}" | fstream_aespass="$aes_password" fstream_aesbuffer="$(($fstream_arg_bufsize - 16))" "$sys_python" fstream-util-pipe_to_aes.py | "$sys_python" fstream.py "fier.me:61920" broadcast
|
|
|
|
else
|
|
|
|
"${enc_cmd[@]}" | "$sys_python" fstream.py "fier.me:61920" broadcast
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
done
|