Search code examples
bashshellubuntuffmpegstream

How to the stream should be automatically restart after 10 seconds if the stream cut


I will restart using this script . But sometime for some reason the stream goes cut....

How to the stream should be automatically restart after 10 seconds if the stream cut.

#!/bin/bash
while true;do
grep -c "Non-monotonous DTS in output stream" file.txt >nonmonotonus.txt
grep -c "Timestamps are unset in a packet for stream" file.txt >timestamp.txt
grep -c "PES packet size mismatch" file.txt >pespacket.txt
grep -c "Error while decoding stream" file.txt >errordecoding.txt
grep -c "Circular buffer overrun" file.txt >circularbuffer.txt
grep -c "Header missing" file.txt >header.txt
grep -c "Conversion failed" file.txt >conversion.txt

file=nonmonotonus.txt
file1=timestamp.txt
file2=pespacket.txt
file3=errordecoding.txt
file4=circularbuffer.txt
file5=header.txt
file6=conversion.txt

if (($(<"$file")>=3000)) || (($(<"$file1")>=500)) || (($(<"$file2")>=100)) || (($(<"$file3")>=1000)) || (($(<"$file4")>=500)) || (($(<"$file5")>=6)) || (($(<"$file6")>=1)); then
stream1 restart > restart.txt
sleep 1
fi
done
__________________________________________________________________________

FFmpeg -re -threads 3 -c:s webvtt -i "$INPUT_URL?source=null&overrun_nonfatal=1&fifo_size=1000000" \
  -c:v copy \
  -map 0:0 -map 0:1  \
  -c:a aac -b:a 128k -ar 48000 \
  -threads 4 -f hls -hls_time 2 -hls_wrap 15 \
  "manifest.m3u8" \
</dev/null > /dev/null 2>&1 2>file.txt & echo $! > $STREAM_PID_PATH

How to automatically restart the stream.. after cut the .ts file

Thankyou ...


Solution

  • Use This Command... easy way to restart the stream :

    $find /path/directory/stream_Location/Stream1.ts -type f -mtime +10 -exec /usr/local/bin/Stream_restart {} \;