quick-jibri-installer/tools/jibri-resolution-enhancer.sh

124 lines
3.7 KiB
Bash
Raw Permalink Normal View History

2021-05-03 22:56:12 +00:00
#!/bin/bash
# Simple Jibri resolution enhancer
2024-03-21 20:09:38 +00:00
# SwITNet Ltd © - 2024, https://switnet.net/
2021-05-03 22:56:12 +00:00
# GNU GPLv3 or later.
while getopts m: option
do
case "${option}"
in
m) MODE=${OPTARG};;
\?) echo "Usage: sudo bash ./$0 [-m debug]" && exit;;
esac
2021-05-03 22:56:12 +00:00
done
#DEBUG
if [ "$MODE" = "debug" ]; then
set -x
2021-05-03 22:56:12 +00:00
fi
#Check if user is root
if ! [ "$(id -u)" = 0 ]; then
2021-05-03 22:56:12 +00:00
echo "You need to be root or have sudo privileges!"
exit 0
fi
# Make sure jibri is installed
if [ "$(dpkg-query -W -f='${Status}' jibri 2>/dev/null | grep -c "ok installed")" == "1" ]; then
echo "Good Jibri is installed on this server"
else
echo "Jibri is not on this system, it is a requirement.
Exiting..."
exit
fi
2021-05-06 07:00:05 +00:00
apt-get -y install apt-show-versions
2021-05-03 22:56:12 +00:00
JIBRI_OPT="/opt/jitsi/jibri"
JIBRI_ENH_PATH="/opt/jibri-res-enhancer"
INSTALLED_JIBRI_VERSION="$(apt-show-versions jibri|awk '{print$2}')"
#Check if already run
if [ -f "$JIBRI_OPT/jibri-res_enh.jar" ] && \
[ -d "$JIBRI_ENH_PATH" ]; then
echo "Seems this tools have been run before..."
exit
fi
mkdir /tmp/jibri
cd /tmp/jibri || exit
2021-05-03 22:56:12 +00:00
#Get md5sum for current jibri installed.
apt-get download jibri="$INSTALLED_JIBRI_VERSION"
2021-05-03 22:56:12 +00:00
ar x jibri_*.deb
tar xvf data.tar.xz
2021-05-06 07:16:52 +00:00
UPSTREAM_DEB_JAR_SUM="$(md5sum 2>/dev/null /tmp/jibri/opt/jitsi/jibri/jibri.jar |awk '{print$1}')"
2021-05-03 22:56:12 +00:00
if [ -z "$UPSTREAM_DEB_JAR_SUM" ]; then
2021-05-03 22:56:12 +00:00
echo "Not possible to continue, exiting..."
exit
fi
#Compile requisites
apt-get -y install devscripts \
git \
maven \
openjdk-11-jdk
2021-05-03 22:56:12 +00:00
#Build repository
git clone https://github.com/jitsi/jibri "$JIBRI_ENH_PATH"
cd "$JIBRI_ENH_PATH" || exit
2021-05-03 22:56:12 +00:00
# Default values
## videoEncodePreset - "veryfast" || h264ConstantRateFactor - 25
# Recomemended values based on: https://trac.ffmpeg.org/wiki/Encode/H.264#crf
## videoEncodePreset - "medium" || h264ConstantRateFactor - 17
2021-05-03 22:56:12 +00:00
sed -i "/videoEncodePreset/s|String =.*|String = \"medium\",|" src/main/kotlin/org/jitsi/jibri/capture/ffmpeg/FfmpegCapturer.kt
sed -i "/h264ConstantRateFactor/s|Int =.*|Int = 17,|" src/main/kotlin/org/jitsi/jibri/capture/ffmpeg/FfmpegCapturer.kt
2021-05-03 22:56:12 +00:00
mvn package
JIBRI_JAR="$(find "$JIBRI_ENH_PATH" -name \*.jar|awk '/dependencies/{print}'|awk 'NR==1{print}')"
cp "$JIBRI_ENH_PATH"/target/"$JIBRI_JAR" "$JIBRI_ENH_PATH"/target/jibri.jar
2021-05-03 22:56:12 +00:00
# Backing up default binaries
2021-05-06 07:25:02 +00:00
if [ "$UPSTREAM_DEB_JAR_SUM" = "$(md5sum 2>/dev/null $JIBRI_OPT/jibri.jar|awk '{print$1}')" ]; then
cp "$JIBRI_OPT"/jibri.jar "$JIBRI_OPT"/jibri-dpkg-package.jar
2021-05-03 22:56:12 +00:00
fi
# Migrate original to enhanced jibri
cp "$JIBRI_ENH_PATH"/target/jibri.jar "$JIBRI_OPT"/jibri-res_enh.jar
if [ -f "$JIBRI_OPT"/jibri-dpkg-package.jar ];then
cp "$JIBRI_OPT"/jibri-res_enh.jar "$JIBRI_OPT"/jibri.jar
2021-05-03 22:56:12 +00:00
fi
2021-05-06 07:48:22 +00:00
JIBRI_RES_ENH_HASH="$(md5sum 2>/dev/null $JIBRI_OPT/jibri-res_enh.jar|awk '{print$1}')"
USED_JIBRI_HASH="$(md5sum 2>/dev/null $JIBRI_OPT/jibri.jar|awk '{print$1}')"
2021-05-03 22:56:12 +00:00
if [ "$JIBRI_RES_ENH_HASH" = "$USED_JIBRI_HASH" ]; then
echo "Everything seems to have gone well."
else
echo "Something went wrong, restoring default package..."
2021-05-06 07:48:22 +00:00
if [ "$(md5sum 2>/dev/null $JIBRI_OPT/jibri-dpkg-package.jar|awk '{print$1}')" = "$UPSTREAM_DEB_JAR_SUM" ]; then
cp "$JIBRI_OPT"/jibri-dpkg-package.jar "$JIBRI_OPT"/jibri.jar
2021-05-06 07:16:52 +00:00
CLEAN="true"
2021-05-03 22:56:12 +00:00
else
if [ -f /tmp/jibri/opt/jitsi/jibri/jibri.jar ]; then
echo "Restoring from upstream package..."
cp /tmp/jibri/opt/jitsi/jibri/jibri.jar "$JIBRI_OPT"/jibri.jar
2021-05-06 07:16:52 +00:00
CLEAN="true"
2021-05-03 22:56:12 +00:00
else
2021-05-22 20:50:42 +00:00
echo "Wow, someone took the time to avoid restoration, please manually review your changes."
2021-05-03 22:56:12 +00:00
echo "Exiting..."
exit
fi
fi
fi
2021-05-06 07:16:52 +00:00
if [ "$CLEAN" = "true" ]; then
rm -r /tmp/jibri
rm -r "$JIBRI_ENH_PATH"
2021-05-06 07:16:52 +00:00
rm /opt/jitsi/jibri/jibri-res_enh.jar
fi
2021-05-06 07:55:22 +00:00
systemctl restart jibri
echo "This will be a good time to test the enhanced resolution."