在终端中使用 vlc 打开 url 错误 [英] open url error using vlc in terminal

查看:49
本文介绍了在终端中使用 vlc 打开 url 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

如果url不正确则写出:

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.

如果url正确则写出:

if the url is correct is writes out:

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

如果 url 没问题,我如何在运行命令(例如在 python 脚本中)后获得?

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

提前致谢!

推荐答案

我们需要检查两件事.

  • 1) 如果 URL 本身是活动的
  • 2) 如果 URL 是活动的,则是数据流(您可能已断开链接).

1) 检查 URL 是否有效.我们可以检查状态代码.任何 2xx 或 3xx 都很好(您可以根据自己的需要进行调整).

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

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.

这是我的其他发帖.

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

这篇关于在终端中使用 vlc 打开 url 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆