Tip: how to customize ffmpeg without changing Jibri's code

I tried the following method on my Debian system and it works.

Create the file /usr/local/bin/ffmpeg

#!/bin/bash

echo $@ >> /tmp/ffmpeg.log

ARGS=$@
#ARGS=$(echo "$ARGS" | sed 's/-s 1280x720/-s 854x480/')

exec /usr/bin/ffmpeg $ARGS

and set the execute permissions

chmod 755 /usr/local/bin/ffmpeg
  • The echo line is only to watch what is coming from Jibri
  • Customize the ARGS value according to your needs. For example the commented sed line changes the resolution from 1280x720 to 854x480
  • You can add some parameters too. For example you can add multiple stream destinations.
6 Likes

Stream and record at the same time

#!/bin/bash

ARGS=$@
RDIR="/tmp/recordings"

if [[ -n "$(echo $ARGS | grep 'rtmp://')" ]]; then
    STREAM=$(echo $ARGS | egrep -o '[^/]*$')
    SUID=$(echo "$STREAM-$(date '+%s')" | md5sum | awk '{print $1}')
    SUBDIR="$RDIR/$SUID"
    mkdir -p $SUBDIR
    FILE="$SUBDIR/$SUID.mp4"

    ARGS="$ARGS -acodec aac -strict -2 -ar 44100"
    ARGS="$ARGS -c:v libx264 -preset veryfast -profile:v main -level 3.1"                                                              
    ARGS="$ARGS -pix_fmt yuv420p -r 30 -crf 25 -g 60 -tune zerolatency"                                                                
    ARGS="$ARGS -f mp4 $FILE"
fi

exec /usr/bin/ffmpeg $ARGS
4 Likes

@emrah nice job! Could you integrate your script to stream and record at the same time with this How do I change YOUTUBE Live Stream to another RTMP server url??

Option to stream to an alternative RTMP server without breaking the YouTube support.

#!/bin/bash

ARGS=$@

if [[ -n "$(echo $ARGS | grep 'rtmp://.*://')" ]]; then
    DST_RAW=$(echo $ARGS | rev | awk '{print $1}' | rev)
    DST=$(echo $DST_RAW | sed 's~^[^:/]*://~~' | egrep -o '[^:/]*://.*')

    ARGS=$(echo $ARGS | sed "s~rtmp://.*~~")
    ARGS="$ARGS $DST"
fi

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

How it’s working

  • Use the Youtube’s live stream key to stream to Youtube
  • Use an RTMP address to stream to the alternative RTMP server
4 Likes

near little script

please take a look at what i’ve done. you can maybe make it easier.

1 Like

it seem’s great. Thank you for sharing your experience with us. can we use these codes if we install Jitsi and Jibri with docker?

I haven’t tried the Docker installation but it should work

1 Like

Hi @emrah, thanks for this!
Question: what would be the code to ensure 720p recording always?

This is related in the sender part which is configured in /etc/jitsi/meet/YOUR-DOMAIN-config.js

resolution, constraints etc.

1 Like

Aaaah I see… so that config setting drives the recording resolution too.

Thanks @emrah!

Hi every one.
I install jitsi and jibri and wish for streaming on my own rtmp server. but in advance i have a problem, please guide me if you can.
i get an error message when i want to record something, it says :Recording failed to start and recording unavailable.
An other issue is that during the jibri installation, when i have to make changes the file in /etc/jitsi/jibri/config.json , this file does not exist at all, and i have to create it my self.
This file does not even exist in the Github documents, but it is a part of installation instruction.
May the recording problem be related to this issue?
Any tips on solving my recording problem will make me happy and thankful.

Hello @Elmira,

This is irrelevant to this topic and a very frequently asked question. There are many topics related in your issue on the forum.

hi @emrah
you are right, excuse me. my final aim is streaming in my local rtmp server. and i really don’t understand what should i do for my problem…jibri couldn’t restart correctly and may be it is because of new config file of Jibri or i should use a dedicated server with public IP. i wonder if you give me any tips…i asked these question in other topic but can not find any solution.