Skip to content

Instantly share code, notes, and snippets.

@tetsu-koba
Last active June 16, 2022 15:10
Show Gist options
  • Save tetsu-koba/83f79aa265b5a2bc3fcec00e95ef2cec to your computer and use it in GitHub Desktop.
Save tetsu-koba/83f79aa265b5a2bc3fcec00e95ef2cec to your computer and use it in GitHub Desktop.
Rec and send SRT with retry
#!/bin/sh -xue
HOST_IP=xx.yy.zz.ww
PORT=7001
RECDIR=$PWD/rec
SEGMENT_TIME=3600
filename="$RECDIR/d%04d.m2ts"
index_wrap=10000
last_index=`ls -t $RECDIR/d[0-9]*.m2ts |head -1 |sed -n -e 's/\.m2ts$//' -e 's/[^0-9]//gp'`
if [ -z $last_index ] ; then
mkdir -p $RECDIR
next_index=0
else
next_index=`echo "($last_index + 1) % $index_wrap" |bc`
fi
touch $RECDIR/start_${next_index}_$(date +%Y%m%d%H%M%S)
libcamera-vid -t 0 --rotation 0 --width 1280 --height 720 --framerate 30 -b 1500000 -g 60 --inline -o - | \
ffmpeg -loglevel repeat+level+error -probesize 32 -f h264 -r 30 -i - -c copy -f tee -map 0:v \
"[f=segment:segment_time=$SEGMENT_TIME:segment_start_number=$next_index:segment_wrap=$index_wrap]$filename|\
[use_fifo=1:f=fifo:fifo_options='drop_pkts_on_overflow=1:attempt_recovery=1:\
recovery_wait_time=5:restart_with_keyframe=1:fifo_format=mpegts']srt://$HOST_IP:$PORT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment