简体   繁体   English

使用PHP检查mms流是否存在

[英]Check if mms stream exists or not using PHP

I am trying to write a php script to test if an mms:// stream exists or not. 我正在尝试编写一个PHP脚本来测试是否存在mms://流。 I have not been able to do it using php functions such as socket_connect/fopen/fsockopen/etc. 我无法使用php函数(例如socket_connect / fopen / fsockopen / etc)来做到这一点。 I have been searching the web for hours now and found similar questions in other forums but no one has actually given an answer (or even whether this is possible). 我已经在网上搜索了几个小时,在其他论坛上也发现了类似的问题,但是没有人给出答案(甚至是不可能的答案)。

This is a possible code that I've used with no luck: 这是我没有运气的可能的代码:

PHP Code: PHP代码:

<?php
$socket = socket_create(AF_INET, SOCK_RAW, 1);
if(!$connect = socket_connect($socket, "mms://some.mms/stream", 1755) )
{
    echo 'Offline';
}
else
{
    echo 'Online';
}
?>

You may want to look into using a video player with command line functionality, such as VLC. 您可能需要考虑使用具有命令行功能的视频播放器,例如VLC。 You can access it via PHP's intrinsic 'exec' function and parse the result. 您可以通过PHP的固有“ exec”函数访问它并解析结果。 Alternatively, you could also use the FFMPEG library to open a stream and determine whether or not it exists/can be played. 或者,您也可以使用FFMPEG库打开一个流,并确定它是否存在/可以播放。

FFMPEG: http://ffmpeg-php.sourceforge.net/ FFMPEG: http//ffmpeg-php.sourceforge.net/
VLC: http://www.videolan.org/vlc/ VLC: http//www.videolan.org/vlc/

Our company specializes in online streaming video and these we've run into some of the same issues; 我们公司专门从事在线流媒体视频,而这些我们也遇到了一些相同的问题; should give you a good starting point. 应该给您一个很好的起点。

Also, here's a VERY OOOOOOOOLD bit of code I wrote to help us validate RTSP streams using PHP's socket_connect. 另外,这是我编写的非常有用的代码,以帮助我们使用PHP的socket_connect验证RTSP流。 You might derive some use out of it. 您可能会利用它。

final static public function validateRTSP($url)
{
$url_bits = parse_url($url);

$port = isset($url_bits['port']) ? $url_bits['port'] : 554;

if(false == isset($url_bits['host']))
{
    throw new Exception("The URL `{$url}` does not have a valid host assignment.");
}

if(isset($url_bits['host']))
{
    if(false === $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP))
    {
        socket_close($socket);

        throw new Exception('A socket could not be opened: ' . socket_strerror(socket_last_error($socket)));
    }

    if(false === socket_connect($socket, $url_bits['host'], $port))
    {
        socket_close($socket);

        throw new Exception("A connection could not be established to {$url_bits['host']}: " . socket_strerror(socket_last_error($socket)));
    }

    $headers = array();

    $headers[] = "DESCRIBE {$url} RTSP/1.0";
    $headers[] = "User-Agent: WMPlayer/12.00.7600.16385 guid/3300AD50-2C39-46C0-AE0A-39E48EB3C868";
    $headers[] = "Accept: application/sdp";
    $headers[] = "Accept-Charset: UTF-8, *;q=0.1";
    $headers[] = "X-Accept-Authentication: Negotiate, NTLM, Digest";
    $headers[] = "Accept-Language: en-US, *;q=0.1";
    $headers[] = "CSeq: 1";
    $headers[] = "Supported: com.microsoft.wm.srvppair, com.microsoft.wm.sswitch, com.microsoft.wm.eosmsg, com.microsoft.wm.predstrm, com.microsoft.wm.fastcache, com.microsoft.wm.locid, com.microsoft.wm.rtp.asf, dlna.announce, dlna.rtx, dlna.rtx-dup, com.microsoft.wm.startupprofile";

    $headerString = implode("\r\n", $headers) . "\r\n\r\n";

    if(false === socket_write($socket, $headerString, strlen($headerString)))
    {
        socket_close($socket);

        throw new Exception("Could not send headers to {$url_bits['host']}: " . socket_strerror(socket_last_error($socket)));
    }


    $response = '';

    if(false === socket_recv($socket, $response, 2048, MSG_WAITALL))
    {
        socket_close($socket);

        throw new Exception("Could not read response from {$url_bits['host']}: " . socket_strerror(socket_last_error($socket)));
    }

    socket_close($socket);


    self::$passes[] = array
    (
        'request' => $headerString,
        'response' => $response
    );


    if(preg_match_all('#^RTSP/.*\s+302+\s#i', $response, $match))
    {
        preg_match_all('#(Location:\s(.*))\r\n#i', $response, $redirect_match);

        return self::url($redirect_match[2][0]);
    }

    if(false == preg_match('#^RTSP/.*\s+[200]+\s#i', $response))
    {
        throw new Exception("URL `{$url}` is invalid.");
    }

    if($attributes = array_pop(explode("\r\n\r\n", $response)))
    {
        preg_match_all("#([a-z]{1})={1}(.+)#i", $attributes, $all);

        self::$attributes = $all[0];
    }

    return true;
}

I would recommend looking at implementing MMS in PHP . 我建议您考虑在PHP实现MMS This should give you guidance to check the existance of a file (using the cURL library). 这应该为您提供指导,以检查文件的存在(使用cURL库)。

EDIT 编辑

Also, it appears the Microsoft Media Server (MMS) protocol isn't very well-known, and people have had problems trying to do what you are . 另外,看来Microsoft Media Server (MMS)协议并不是很知名,人们在尝试做自己的工作时遇到了问题 Only recommendation (and I guess shot in the dark) would be use fsockopen and check for a response and go by that, otherwise it's a shot in the dark. 唯一的建议(我猜是在黑暗中拍摄)将使用fsockopen并检查响应并接受,否则,它是在黑暗中拍摄。 As the linked Wikipedia page suggests, there are some who have tried reverse engineering the protocol, those may be your best bet. 正如链接的Wikipedia页面所建议的那样,有些人尝试过对该协议进行逆向工程,这可能是您最好的选择。

Check the documentation of socet_connect() . 检查socet_connect()文档 The second parameter (address) must be an IPv4 or IPv6 address. 第二个参数(地址)必须是IPv4或IPv6地址。 I don't have experience with the mms stream, but my guess would be to connect to the server (with its IP) and then send the name of the socket (everything after mms://) to the server. 我对mms流没有经验,但是我的猜测是连接到服务器(及其IP),然后将套接字的名称(mms://之后的所有内容)发送到服务器。 I'd need more details about the MMS stream to assist you further. 我需要有关MMS流的更多详细信息,以进一步为您提供帮助。

You cannot use the mms:// URL as second parameter. 您不能使用mms:// URL作为第二个参数。 socket_connect() only takes a network address or server name there. socket_connect()仅在其中使用网络地址或服务器名称。 With that raw socket function you can at best connect to the port, but not interact with a MMS server. 使用该原始套接字功能,您最多可以连接到端口,但不能与MMS服务器进行交互。 Thus checking for the file path is not possible, unless you study this: http://msdn.microsoft.com/en-us/library/cc234711(PROT.10).aspx (At first glance a typical Microsoft binary protocol, with fixed width and/or null terminated strings.) 因此,除非您进行以下研究,否则无法检查文件路径: http : //msdn.microsoft.com/zh-cn/library/cc234711PROT.10).aspx (乍一看,典型的Microsoft二进制协议具有固定宽度和/或null终止的字符串。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM