open url error using vlc in terminal

懵懂的女人 提交于 2019-12-11 05:33:15

问题


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-ratio=24 --scene-path=/home/pi/Desktop vlc://quit

If the url is okay, it makes some pictures from streams. I would like to know if the command ran successfully or not.

if the url is not correct is writes out:

[73b00508] core input error: open of 'http://streamx/live/....stream/playlist.m3u8' failed
[73b00508] core input error: Your input can't be opened
[73b00508] core input error: VLC is unable to open the MRL 'http://streamx/live/....stream/playlist.m3u8'. Check the log for details.

if the url is correct is writes out:

[73b03f20] httplive stream: HTTP Live Streaming (streamx/live/....stream/playlist.m3u8)

How can I get after running the command (for example in a python script) if the url was okay or not?

Thanks in advance!


回答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()


来源:https://stackoverflow.com/questions/46203610/open-url-error-using-vlc-in-terminal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!