在终端中使用vlc打开url错误

时间:2017-09-13 17:30:05

标签: python vlc

我在linux终端中运行以下命令:

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

如果网址没问题,它会从流中制作一些图片。我想知道命令是否成功运行。

如果网址不正确则写出:

[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.

如果网址正确则写出:

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

如果网址没有问题,我怎样才能运行命令(例如在python脚本中)?

提前致谢!

1 个答案:

答案 0 :(得分:0)

我们需要检查两件事。

  • 1)如果URL本身还活着
  • 2)如果URL处于活动状态,则是数据流(您可能已断开链接)。

1)检查URL是否存活。我们可以查看状态代码。任何2xx或3xx都是好的(你可以根据自己的需要定制)。

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)现在我们有了很好的网址,但是我们需要检查一下我们是否有流媒体和链接没有死 使用VLC,我们可以连接到站点,尝试在链接上播放媒体,然后检查错误。

以下是我other发布的一个工作示例。

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