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

open url error using vlc in terminal

我在 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

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

如果url不正确则写出:

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

如果 url 正确则写出:

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

在 运行 执行命令后(例如在 python 脚本中)我怎样才能知道 url 是否正常?

提前致谢!

我们需要检查两件事。

  • 1) 如果URL本身还活着
  • 2)如果URL是活着的,就是数据流(你可能已经坏了link)。

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

这是我的 帖子中的一个工作示例。

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