Created
June 14, 2022 11:59
-
-
Save tetsu-koba/fb84349b6ace0c026b085fa98126d6fc to your computer and use it in GitHub Desktop.
rec and send SRT by ffmpeg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -xue | |
HOST_IP=xx.yy.zz.ww | |
PORT=7001 | |
RECDIR=$PWD/rec | |
SEGMENT_TIME=3600 | |
FIFO=$PWD/.fifo | |
rm -f $FIFO | |
mkfifo $FIFO | |
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) | |
ffmpeg -loglevel repeat+level+error -probesize 32 -f hevc -r 30 -i $FIFO -c copy -f tee -map 0:v \ | |
"[f=segment:segment_time=$SEGMENT_TIME:segment_start_number=$next_index:segment_wrap=$index_wrap]$filename|\ | |
[f=mpegts]srt://$HOST_IP:$PORT" & | |
gst-launch-1.0 -eq v4l2src device="/dev/video0" ! \ | |
'image/jpeg, width=1280, height=720, framerate=30/1' ! \ | |
nvv4l2decoder mjpeg=1 ! 'video/x-raw(memory:NVMM)' ! \ | |
nvvidconv ! 'video/x-raw(memory:NVMM), format=(string)I420' ! \ | |
nvv4l2h265enc insert-sps-pps=1 iframeinterval=60 bitrate=1000000 ! \ | |
queue2 ! filesink location=$FIFO | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment