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.
7 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
5 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
5 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.

Does anybody know how to use it with docker jibri ?

@Elmira check out this tutorial - pretty certain it will help you fix your Jibri problem:

Thanks a lot for your solution, the use of the path is really clever, well done :slight_smile:

You can encode once and send it to 2 outputs:

https://trac.ffmpeg.org/wiki/Creating%20multiple%20outputs#Duplicateoutputs

But I just couldn’t figure out :confused:

Also your option to stream and record, I couldn’t make it work more than 30minutes without error.

At the end, I used your script to tune a bit the params of ffmpeg, it was already really useful :slight_smile:

And by the way, now jibri supports rtmp linl directly, no need for this if you are good with the default options :slight_smile: didn’t see it documented here, but on peertube :wink:

1 Like

I tested this before but it doesn’t work with ffmpeg from Debian repo.

Now, I stream to my stream server and multiply it on the stream server.
installing a live streaming media system

arf, I though about this possibility, but as the feature is in ffmpeg since 2013… I though it would be in debian :slight_smile: thanks for the information.

Nice, and thanks for sharing!
Just for information a friend recommended me:

2 Likes

Hi,@emrah sir
can you guide me i am using jibri as Docker.I want to do livestream with my own media server(red5) instead of youtube.How to do can you give some brief idea or share some document relate to this.i am getting confuse.

I’m not familar with Docker installation. If jibri is the latest version in Docker, you should not need to do anything. Just use the whole RTMP link as a stream name