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.
4 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
3 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
2 Likes

near little script

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

1 Like