Skip to content

Instantly share code, notes, and snippets.

@thanosa75
Created May 22, 2020 15:05
Show Gist options
  • Save thanosa75/7efaaa9720b6ebf6d9e6293afaa3b55b to your computer and use it in GitHub Desktop.
Save thanosa75/7efaaa9720b6ebf6d9e6293afaa3b55b to your computer and use it in GitHub Desktop.
Jitsi Meet (Jibri) 'finalize.sh' script - a script that is executed just after the recording is completed.
#!/bin/bash
#
# BSD 3-clause LICENSE
# Copyright 2020 A. Angelatos (agelatos at g-mail-com)
#
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that
# the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
# disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
# following disclaimer in the documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
# products derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# --end of license--
# Jibri will call us with $1 as the directory of the recording.
DIR=$1
echo "Recording processor for recording of directory $DIR"
## encoding quality (lower == better)
# 23 is about 1.5x aka 45 FPS average on my hardware (6 core 12 thread Xeon 2.6GHz)
QENC=23
#scaling (captured video is 720p)
#this one scales to 360p (divides by 2 both dimensions, keeping aspect 16:9)
#VSCALE="-vf scale=iw/2:-1"
#this one scales to 960p
VSCALE="-vf scale=960:-1"
# note destination is within the container - so you should mount (bind mount) something to it or handle appropriately
# this destination moves the file to 'recordings' directory
DEST="$(cd $DIR && cd .. && pwd)"
echo "Processing from $DIR to $DEST"
# here we find the mp4 file and convert it using x265 at configured scale and quality, leaving audio and framerate as is
find "$DIR" -name "*mp4" -print0 | xargs -i'{}' -0 ffmpeg -i '{}' -c:v libx265 -crf $QENC -c:a copy $VSCALE '{}'.scaled.mp4
echo "moving to destination directory $DEST"
find "$DIR" -name "*scaled.mp4" -print0 | xargs -i'{}' -0 mv '{}' $DEST/`date +%y%m%d_%H%M`_meeting.mp4
echo "Removing original files"
find "$DIR" -name "*mp4" -print0 | xargs -i'{}' -0 rm -f '{}'
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment