HomeAuthorsContact
WebRTC
Jibri Streaming To Custom RMTP Endpoint
Supun Madusanka
August 03, 2020
1 min

Introduction

Jibri is the component of jitsi which handles both recording and streaming capabilities. Current Jibri supports Youtube streaming by providing streaming key to Jitsi meet. If we want to stream to a custom RTMP endpoint and record simultaneously, you can follow the below instructions. Here we have used Nginx as the RTMP server. The instructions are in the following order.

  1. Jibri
  2. nginx rtmp
  3. FFmpeg

How to do This

Set up jibri

Install Jibri on ubuntu 18.04. Follow Jibri installation instructions here

Set up nginx

Now let’s setup a nginx RTMP server

apt install build-essential libpcre3 libpcre3-dev libssl-dev nginx libnginx-mod-rtmp ffmpeg -y

Insert the follwing 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;
        }
    }
}
mkdir -p /var/www/html/recordings
chown -R www-data:www-data /var/www/html/recordings/

Write custom ffmpeg script

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


Record streaming

Add below application live block and you can run node app

on_record_done http://127.0.0.1:3000/recorded; 

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();
});

This is the script to upload record stream video to 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


Reference

I followed this community-post

Thank you support for the support given emrah



Tags

jitsijibristreaming

Supun Madusanka

CTO

Expertise

WebRTC
Javascript
React
AWS

Social Media

gitlabgithublinkedin

Related Posts

WebRTC
Jitsi Recorder Server/Jibri AutoScale using aws
May 01, 2020
1 min
© 2021, All Rights Reserved.

Legal Stuff

Privacy NoticeCookie PolicyTerms Of Use

Social Media