#!/bin/bash
touch /tmp/ffmpeg.log
ffmpeg -shortest -re -y -err_detect aggressive -i \
rtmp://127.0.0.1/movies/my.stream timeout=10 -codec copy \
-map 0 -bsf:v h264_mp4toannexb,dump_extra -f segment \
-segment_time 60 -progress /tmp/ffmpeg.log /video/my.stream#%09d.ts &
pid=$!
while true
do
# you'll might have to change "invalid"
# for whatever is being put into the progress log
# just look at /tmp/ffmpeg.log to figure out what
# grep should try to find
error=$(grep -n "invalid" /tmp/ffmpeg.log)
# is the length of the error more than 0 / did grep find it???
if (( ${#error} > 0 ))
then
kill -9 $pid
ffmpeg -shortest -re -y -err_detect aggressive -i \
rtmp://127.0.0.1/movies/my.stream timeout=10 -codec copy \
-map 0 -bsf:v h264_mp4toannexb,dump_extra -f segment \
-segment_time 60 -progress /tmp/ffmpeg.log /video/my.stream#%09d.ts &
pid=$!
else
usleep 100
fi
done
exit 0
-err_detect aggressive
и -progress /tmp/ffmpeg.log
, остальное можете переделывать под себя. nginx и все остальное - по вкусу. 2>>/tmp/ffmpeg.log
ошибок не выдает, при отсутствии потока он просто перестает писаться, а -progress /tmp/ffmpeg.log
отличается от предыдущего? Попробую.application stream {
live on;
hls on;
sync 5ms;
hls_path /usr/tmp/hls/stream/;
exec_static ffmpeg -re -i rtsp://admin:admin@ip:port -c copy -f flv -an -err_detect aggressive -progress /tmp/ffmpeg_error.log rtmp://localhost:1935/stream/stream 2>>/tmp/stream.log;
}
while true; do
if kill -0 $pid ; then
sleep 10
else
ffmpeg -shortest -re -y -err_detect aggressive -i \
rtmp://127.0.0.1/movies/my.stream timeout=10 -codec copy \
-map 0 -bsf:v h264_mp4toannexb,dump_extra -f segment \
-segment_time 60 -progress /tmp/ffmpeg.log /video/my.stream#%09d.ts &
pid=$!
fi
done