Open Url Error Using Vlc In Terminal
I run the following command in a linux terminal: vlc http://streamx/live/....stream/playlist.m3u8 --rate=1 --video-filter=scene --vout=dummy --run-time=3 --scene-format=png --scene
Solution 1:
We need to check two things.
- 1) If the URL itself is alive
- 2) If the URL is alive, is the data streaming (you may have broken link).
1) To check if URL is alive. We can check status code. Anything 2xx or 3xx is good (you can tailor this to your needs).
import urllib
url = 'http://aska.ru-hoster.com:8053/autodj'
code = urllib.urlopen(url).getcode()
if str(code).startswith('2') or str(code).startswith('3') :
print 'Stream is working'
else:
print 'Stream is dead'
2) Now we have good URL , but we need to check if we have streaming and link is not dead.
Using VLC, we can connect to site, try to play the media at the link and then check for errors.
Here is a working example that I have from my other posting.
import vlc
import time
url = 'http://aska.ru-hoster.com:8053/autodj'
#define VLC instance
instance = vlc.Instance('--input-repeat=-1', '--fullscreen')
#Define VLC player
player=instance.media_player_new()
#Define VLC media
media=instance.media_new(url)
#Set player media
player.set_media(media)
#Play the media
player.play()
#Sleep for 5 sec for VLC to complete retries.
time.sleep(5)
#Get current state.
state = str(player.get_state())
#Find out if stream is working.
if state == "vlc.State.Error" or state == "State.Error":
print 'Stream is dead. Current state = {}'.format(state)
player.stop()
else:
print 'Stream is working. Current state = {}'.format(state)
player.stop()
Post a Comment for "Open Url Error Using Vlc In Terminal"