【问题标题】:open url error using vlc in terminal在终端中使用 vlc 打开 url 错误
【发布时间】:2018-02-22 12:33:39
【问题描述】:

我在 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 脚本中),我如何获取 url 是否正常?

提前致谢!

【问题讨论】:

  • 使用 wget 之类的东西来检查您是否获得了有效的响应(即不是 500 或 404 等),并且响应编码是您在实际打开 VLC 之前想要的类型。

标签: python vlc


【解决方案1】:

我们需要检查两件事。

  • 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) 现在我们的 URL 很好,但是我们需要检查我们是否有流媒体并且链接没有死。
使用 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()

【讨论】:

  • 感谢您的快速回答,我一定会检查一下!
  • 让我知道它是否有效。如果是这样,请考虑投票并接受答案以结束循环。如果不让我知道问题,以便我可以重新审视问题。
  • 1) 在 python 2 中工作,但是当我在 python 3 中尝试时: import urllib.request with urllib.request.urlopen(url) as url: s = url.read() shell 写什么都没有。你能包括一个python 3解决方案吗?谢谢
  • 对于python3,添加import urllib.request并将code=改为code = urllib.request.urlopen(url).getcode()看看是否有效。
  • 工作流没问题,但我得到 urllib.error.HTTPError: HTTP Error 404: Not Found when stream is down
猜你喜欢
  • 1970-01-01
  • 2021-11-27
  • 2021-02-03
  • 2013-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-07
相关资源
最近更新 更多