Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
auto-restart FFMPEG when it stops sending frames to youtube
sleep 5
ffmpeg -re -f mjpeg -r 10 -i "http://localhost/?action=stream" -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -acodec aac -ab 1k -strict experimental -s 640x360 -vcodec h264 -pix_fmt yuv420p -g 20 -vb 500k -preset ultrafast -crf 31 -r 10 -f flv "rtmp://" 2> /home/pi/ffmpeg.log
sleep 10
while true
frameA=$(tail /home/pi/ffmpeg.log -n 1 | sed -nr 's/.*frame=(.*)fps.*/\1/p')
echo "$frameA"
sleep 5
frameB=$(tail /home/pi/ffmpeg.log -n 1 | sed -nr 's/.*frame=(.*)fps.*/\1/p')
echo "$frameB"
if [ "$frameA" = "$frameB" ]
echo "Stream has hung"
printf "%s - Stream has hung\n" "$(date)" >> stream.log
pkill ffmpeg
echo "killed ffmpeg..."
printf "%s - Killed ffmpeg...\n" "$(date)" >> stream.log
echo "Waiting 5 secs"
sleep 5
bash /home/pi/ &
echo "started ffpmeg.."
printf "%s - Started ffmpeg..\n" "$(date)" >> stream.log
echo "Waiting 15 secs"
sleep 15
echo "Stream looks ok."
sleep 2

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment