Tuesday, May 14, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 2587  / 3 Years ago, sun, september 26, 2021, 12:21:54

I am using rtmpdump to restream live video on my local network on nginx rtmp server. like this:



sudo rtmpdump -r "rtmp://123.45.6.7/live/" -a "live/" -f "LNX 14,0,0,125" -W "http://123.45.6.7/jwplayer.flash.swf[1] " -p "http://123.45.6.7/[2] " --live -y "livestream2" | avconv -i pipe:0 -y
-v:v info -vcodec copy -acodec copy -f flv rtmp://localhost:1935/live/


it works great on its own with no problem but once in a while the original source might flicker and it will cause the running command to quit, and I have to manually run the command again. Is there a way to make a script which will automatically detect if rtmpdump quit and there is no zombie command running and rerun the command?
I want to automate this process for about 4 live streams. Is it possible?


More From » bash

 Answers
4

You could write a script with these contents:



#! /bin/bash
function INT_cleanup()
{
kill `jobs -p`
exit
}

trap INT_cleanup INT

# ${VAR-TEXT} means that TEXT is used if VAR is empty.

STREAM_START=$(($1))
STREAM_END=$(($2))
for ((COUNT=STREAM_START; COUNT<=STREAM_END;COUNT++))
do
while true #Infinite loop
do
rtmpdump -r "rtmp://123.45.6.7/live/" -a "live/" -f "LNX 14,0,0,125" -W
"http://123.45.6.7/jwplayer.flash.swf[1] "
-p "http://123.45.6.7/[2] " --live -y "livestream$COUNT" |
avconv -i pipe:0 -y -v:v info -vcodec copy
-acodec copy -f flv rtmp://localhost:1935/live$COUNT/
done &
done


Or



#! /bin/bash
function INT_cleanup()
{
kill `jobs -p`
exit
}

trap INT_cleanup INT

count=0
while [[ $count < 10 ]] # Try 10 times
do
rtmpdump -r "rtmp://123.45.6.7/live/" -a "live/" -f "LNX 14,0,0,125" -W "http://123.45.6.7/jwplayer.flash.swf[1] " -p "http://123.45.6.7/[2] " --live -y "livestream2" | avconv -i pipe:0 -y -v:v info -vcodec copy -acodec copy -f flv rtmp://localhost:1935/live/
count=$((count + 1))
done


in a file, call it stream.sh, make it executable:



chmod +x stream.sh


and run it:



sudo ./stream.sh 1 3


To kill the script, press CtrlC. The first is an infinite loop, the second runs for 10 iterations.


[#24069] Sunday, September 26, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
peafowkes

Total Points: 356
Total Questions: 102
Total Answers: 117

Location: Lebanon
Member since Tue, Oct 12, 2021
3 Years ago
;