你可能想使用視頻具有命令行功能的播放器,例如VLC。你可以通過PHP的內部'exec'函數訪問它並解析結果。或者,您也可以使用FFMPEG庫打開流並確定它是否存在/可以播放。
FFMPEG:http://ffmpeg-php.sourceforge.net/
VLC:http://www.videolan.org/vlc/
我公司專業從事在線流媒體視頻和這些我們遇到了一些相同的問題;應該給你一個很好的起點。
此外,我寫了一段代碼,用於幫助我們使用PHP的socket_connect驗證RTSP流。你可能會從中得到一些用處。
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;
}