问题
I am using VLC to rebroadcast a stream and this side of things is working very well. After a few hours however, I need to re authenticate and re-request the stream. I have a script that simply needs to be run and this will handle the re-authentication and starting vlc. The problem I am having is how to figure out if the stream is no longer working.
When using say:
pidof vlc
I get the pid of the process VLC. When checking top, I can see VLC running and consuming cpu. However, when I try to play the stream nothing happens. If I run my script again, the stream restarts and I can then watch it again. So even if the stream has stopped, VLC continues to run giving me no indication of whether the stream itself is actually running or just VLC.
The only thing I have spotted so far is that when the stream is not running the CPU usage seems to spike according to top
.
When the stream is running, the cpu usage is around the 1% mark, when it is not running it seems to spike past 40%. I have observed this a couple of times, but I can only assume that this would potentially be a way I could ensure the stream is running, but I am not 100% confident in the approach.
Does anyone have any knowledge on how I could confirm if the actual stream is running or if it is just the VLC process?
回答1:
should give credits to @mundu
here is a script I created for checking if vlc is streaming.
// vlc_verify1.sh
#!/bin/bash
VLC_CONF="$1"
VLC_COMMAND="$2"
VLC_PASS="videolan"
echo "" > nohup.out
nohup vlc --intf telnet --vlm-conf $VLC_CONF --telnet-password $VLC_PASS &
vlc_pid=$!
echo "vlc has a pid of $vlc_pid"
sleep 5
echo "nc start"
nc localhost 4212 < $VLC_COMMAND
kill $vlc_pid
exit 0
// vlm-conf, you have to replace $url with the actual url
new channel1 broadcast enabled
setup channel1 input $url
control channel1 play
show
// command.txt
videolan
show
the vlc_verify1.sh
would output the status of current playing as mentioned by @mundu. what I did is to grep the output and see if it's state is 'playing'.
Notice, I didn't specify the output like setup channel1 output #std{access=udp,mux=ts,dst=239.192.174.105:1234}
.
a reason for that is sometime vlc would use 100% cpu time. I have no clue why so. but if I get rid of that, I didn't experience similar issues. a downside for this is that there will be a pop-up window playing the streamings. but I don't think it's a big deal.
回答2:
Easy. Use the VLM interface.
vlc -I telnet --vlm-conf vlm.conf
Adapt your command line to place the sout in your vlm.conf like this example:
new channel1 broadcast enabled
setup channel1 input http://host.mydomain/movie.mpeg
setup channel1 output #std{access=udp,mux=ts,dst=239.192.174.105:1234}
control channel1 play
You can then login to the telnet interface and type show to see the current broadcasts and its status.
> show
show
media : ( 1 broadcast - 0 vod )
channel1
type : broadcast
enabled : yes
loop : yes
inputs
1 : http://host.mydomain/movie.mpeg
output : #std{access=udp,mux=ts,dst=239.192.174.105:1234}
options
instances
instance
name : default
state : playing
position : 0.058974
time : 6473336
length : 109766611
rate : 1.000000
title : 0
chapter : 0
can-seek : 1
playlistindex : 1
You can read more here https://wiki.videolan.org/Documentation:Streaming_HowTo/VLM/
PS: I would increase the log -v(vv) an perhaps use the syslog to save it and track any problems afterwards.
来源:https://stackoverflow.com/questions/31719100/vlc-check-stream-status