Jitsi
Jibri Streaming and Recording To Custom RMTP Endpoint
Supun Madushanka
August 03, 2020
1 min

This post discusses of how to stream to Custom RTMP endpoints with jitsi apart from the supported youtube streaming. We use the component Jibri with configuration changes and some scripts to achieve this functionality(Jibri is the infrascture used to broadcast which includes both recording and streaming) You can use this to stream the video from jitsi meet to custom RTMP endpoints like Wowza, OBS, Vimeo, Ant Media, Nginx etc. In this article we would be using nginx as the RTMP endpoint.

Main components involved

  • Jibri - Broadcasting component of jitsi which is used for both streaming and recording
  • FFmpeg - Component responsible for capturing and encoding the output of virtual framebuffer in jibri
  • Nginx RTMP - Using nginx opensource for video streaming

High Level Architecture

jibri rtmp

The Setup

  • Install Jibri on a EC2 server
  • To setup the Nginx RTMP server follow the below steps,
  1. Execute the following commands to install the libraries
apt install build-essential libpcre3 libpcre3-dev libssl-dev nginx libnginx-mod-rtmp ffmpeg -y
  1. Insert the following code to nginx configs
rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application live {
            live on;
            #Set this to "record off" if you don't want to save a copy of your broadcasts
            record all;
            # The directory in which the recordings will be stored.
            record_path /var/www/html/recordings;
            record_unique on;
            record_suffix -%d-%b-%y-%T.flv;
            on_record_done http://127.0.0.1:3000/recorded;

            # Turn on HLS
            exec /usr/bin/ffmpeg -i rtmp://127.0.0.1/live/$name -crf 30 -preset ultrafast -acodec aac -strict experimental -ar 44100 -ac 2 -b:a 64k -vcodec libx264 -x264-params keyint=60:no-scenecut=1 -r 30 -b:v 500k -s 960x540 -f flv rtmp://yourdomai.com/show/$name;
        }

        application show {
            live on;
            # Turn on HLS
            hls on;
            hls_path /mnt/hls/;
            hls_fragment 3;
            hls_playlist_length 60;
            # disable consuming the stream from nginx as rtmp
            deny play all;
        }
    }
}
  1. Execute the following command to create a folder for recordings
mkdir -p /var/www/html/recordings
chown -R www-data:www-data /var/www/html/recordings/
  • Let’s move on to creating a custom ffmpeg script in jibri to forward the captured video stream to Nginx RTMP server Put below code to location /usr/local/bin/ffmpeg
#!/bin/bash

ARGS=$@

if [[ -n "$(echo $ARGS | grep ' rtmp://')" ]]; then
    DST=$(echo $ARGS | rev | awk '{print $1}' | rev)
    STREAM=$(echo $DST | rev | cut -d '/' -f1 | rev)

    ARGS=$(echo $ARGS | sed "s~rtmp://.*~~")
    ARGS="$ARGS rtmp://127.0.0.1:1935/live/$STREAM"
fi

echo $ARGS >> /tmp/ffmpeg.log
exec /usr/bin/ffmpeg $ARGS

  • Finally let’s record the video streams
  1. Add below application live block and you can run the node app
on_record_done http://127.0.0.1:3000/recorded;
  1. Put below code for express application
app.post('/recorded', async (req, res) => {
  console.log('recorded');
  shell.exec('/home/recorded.sh')
  res.status(200);
  res.send().end();
});
  1. Use this script to upload record stream video to a s3 bucket
## upload script
#!/bin/sh
RECORDINGS_DIR="/var/www/html/recordings/"
/usr/local/bin/aws s3 cp --recursive ${RECORDINGS_DIR} s3://yourbucket
if [ -f /tmp/protect ]; then
    echo "file exist"
        rm /tmp/protect
    else

    echo "file not exist"
    fi
sudo service jibri restart
exit 0

This gives us the ability to stream to a custom RTMP endpoint and record at the same time. Also I should remind the support given by emrah

Reference

If you want to setup a streaming system with jitsi please contact us through support@telzee.io. We provide WebRTC development services and solutions


Tags

jitsijibristreaming

Supun Madushanka

CTO

Expertise

WebRTC
Javascript
React
AWS

Social Media

gitlabgithublinkedin

Related Posts

Customize Jitsi Meet External API
May 01, 2020
1 min