使用php文件读取视频stream并用flowplayer播放
来源:互联网 发布:mac air 增加内存 编辑:程序博客网 时间:2024/05/16 02:59
php文件读取视频留可以原创文章:
http://richbellamy.com/wiki/Flash_Streaming_to_FlowPlayer_using_only_PHP
下面我想说说我是怎么配置成功的:
1. 下载读取视频stream的streamer.php文件:
http://richbellamy.com/wiki/Flowplayer_streamer_php
php代码如下,仔细红色的配置部分:
<?
/*
xmoov-php 0.9
Development version 0.9.3 beta
by: Eric Lorenzo Benjamin jr. webmaster (AT) xmoov (DOT) com
originally inspired by Stefan Richter at flashcomguru.com
bandwidth limiting by Terry streamingflvcom (AT) dedicatedmanagers (DOT) com
Flowplayer compatibility by Rich Bellamy rich (@+) rmbwebs d0t com
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License.
For more information, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
For the full license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode
or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.
*/
// SCRIPT CONFIGURATION
//------------------------------------------------------------------------------------------
// MEDIA PATH
//
// you can configure these settings to point to video files outside the public html folder.
//------------------------------------------------------------------------------------------
// points to server root
//定义你的根目录,一般为你的网站根目录下面的第一个文件,下面这个配置则代表的是http://www.malacity.net/example. 注意前面都没有斜杠
define('XMOOV_PATH_ROOT','example');
// points to the folder containing the video files. Should start and end with '/'
//下面配置的是视频的所在目录 则以下配置后为http://. 注意前后都有斜杠www.malacity.net/example/videos/
define('XMOOV_PATH_FILES', '/videos/');
//------------------------------------------------------------------------------------------
// SCRIPT BEHAVIOR
//------------------------------------------------------------------------------------------
//set to TRUE to use bandwidth limiting.
define('XMOOV_CONF_LIMIT_BANDWIDTH', TRUE);
//set to FALSE to prohibit caching of video files.
define('XMOOV_CONF_ALLOW_FILE_CACHE', FALSE);
//------------------------------------------------------------------------------------------
// BANDWIDTH SETTINGS
//
// these settings are only needed when using bandwidth limiting.
//
// bandwidth is limited my sending a limited amount of video data(XMOOV_BW_PACKET_SIZE),
// in specified time intervals(XMOOV_BW_PACKET_INTERVAL).
// avoid time intervals over 1.5 seconds for best results.
//
// you can also control bandwidth limiting via http command using your video player.
// the function getBandwidthLimit($part) holds three preconfigured presets(low, mid, high),
// which can be changed to meet your needs
//------------------------------------------------------------------------------------------
//set how many kilobytes will be sent per time interval
define('XMOOV_BW_PACKET_SIZE', 90);
//set the time interval in which data packets will be sent in seconds.
define('XMOOV_BW_PACKET_INTERVAL', 0.3);
//set to TRUE to control bandwidth externally via http.
define('XMOOV_CONF_ALLOW_DYNAMIC_BANDWIDTH', TRUE);
define('XMOOV_GET_BANDWIDTH', 'bw');
//------------------------------------------------------------------------------------------
// DYNAMIC BANDWIDTH CONTROL
//------------------------------------------------------------------------------------------
function getBandwidthLimit($part)
{
switch($part)
{
case 'interval' :
switch($_GET[XMOOV_GET_BANDWIDTH])
{
case 'low' :
return 1;
break;
case 'mid' :
return 0.5;
break;
case 'high' :
return 0.3;
break;
default :
return XMOOV_BW_PACKET_INTERVAL;
break;
}
break;
case 'size' :
switch($_GET[XMOOV_GET_BANDWIDTH])
{
case 'low' :
return 10;
break;
case 'mid' :
return 40;
break;
case 'high' :
return 90;
break;
default :
return XMOOV_BW_PACKET_SIZE;
break;
}
break;
}
}
//------------------------------------------------------------------------------------------
// INCOMING GET VARIABLES CONFIGURATION
//
// use these settings to configure how video files, seek position and bandwidth settings are accessed by your player
//
// NOTE TO Flowplayer users: XMOOV_GET_POSITION must be set to 'start' to
// work with Flowplayer, and the other two don't matter
//------------------------------------------------------------------------------------------
define('XMOOV_GET_FILE', 'file');
define('XMOOV_GET_POSITION', 'start');
define('XMOOV_GET_AUTHENTICATION', 'key');
// END SCRIPT CONFIGURATION - do not change anything beyond this point if you do not know what you are doing
//------------------------------------------------------------------------------------------
// PROCESS FILE REQUEST
//------------------------------------------------------------------------------------------
if (isset($_SERVER['PATH_INFO']) || isset($_GET[XMOOV_GET_FILE]))
{
// PROCESS VARIABLES
# get seek position
if (isset($_GET[XMOOV_GET_POSITION])) {
$seekPos = intval($_GET[XMOOV_GET_POSITION]);
} else {
$seekPos = 0;
}
# get file name
if (isset($_SERVER['PATH_INFO'])) {
$fileName = htmlspecialchars(ltrim($_SERVER['PATH_INFO'], "/"));
} else {
$fileName = htmlspecialchars($_GET[XMOOV_GET_FILE]);
}
# assemble file path
$file = XMOOV_PATH_ROOT . XMOOV_PATH_FILES . $fileName;
# assemble packet interval
$packet_interval = (XMOOV_CONF_ALLOW_DYNAMIC_BANDWIDTH && isset($_GET[XMOOV_GET_BANDWIDTH])) ? getBandwidthLimit('interval') : XMOOV_BW_PACKET_INTERVAL;
# assemble packet size
$packet_size = ((XMOOV_CONF_ALLOW_DYNAMIC_BANDWIDTH && isset($_GET[XMOOV_GET_BANDWIDTH])) ? getBandwidthLimit('size') : XMOOV_BW_PACKET_SIZE) * 1042;
# security improved by by TRUI www.trui.net
if (!file_exists($file))
{
print('<b>ERROR:</b> xmoov-php could not find ('.$file.') please check your settings.');
exit();
}
if(file_exists($file) && strrchr($fileName, '.') == '.flv' && strlen($fileName) > 2 && !eregi(basename($_SERVER['SCRIPT_NAME']), $fileName) && ereg('^[^./][^/]*$', $fileName))
{
$fh = fopen($file, 'rb') or die ('<b>ERROR:</b> xmoov-php could not open (' . $fileName . ')');
$fileSize = filesize($file) - (($seekPos > 0) ? $seekPos + 1 : 0);
// SEND HEADERS
if(!XMOOV_CONF_ALLOW_FILE_CACHE)
{
# prohibit caching (different methods for different clients)
session_cache_limiter("nocache");
header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
}
# content headers
header("Content-Type: video/x-flv");
header("Content-Disposition: attachment; filename=/"" . $fileName . "/"");
# FLV file format header
if($seekPos != 0)
{
header("Content-Length: " . ($fileSize + 13));
print('FLV');
print(pack('C', 1));
print(pack('C', 1));
print(pack('N', 9));
print(pack('N', 9));
}
else
{
header("Content-Length: " . $fileSize);
}
# seek to requested file position
fseek($fh, $seekPos);
# output file
while(!feof($fh))
{
# use bandwidth limiting - by Terry
if(XMOOV_CONF_LIMIT_BANDWIDTH)
{
# get start time
list($usec, $sec) = explode(' ', microtime());
$time_start = ((float)$usec + (float)$sec);
# output packet
print(fread($fh, $packet_size));
# get end time
list($usec, $sec) = explode(' ', microtime());
$time_stop = ((float)$usec + (float)$sec);
# wait if output is slower than $packet_interval
$time_difference = $time_stop - $time_start;
if($time_difference < (float)$packet_interval)
{
usleep((float)$packet_interval * 1000000 - (float)$time_difference * 1000000);
}
}
else
{
# output file without bandwidth limiting
while (!feof($fh)) {
print fread($fh, 8192);
}
}
}
}
}
?>
2 . 上传一个myvideo.flv文件到videos文件夹中
3. 配置完后你可以通过测试:
http://www.malacity.net/streamer.php/myvideo.flv
查看是否可以下载你所上传的文件?如果能下载则表面你创建的tream成功了.
4. 配置flowplayer:注意红色说明.
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!-- A minimal Flowplayer setup to get you started -->
<!--
include flowplayer JavaScript file that does
Flash embedding and provides the Flowplayer API.
-->
<script type="text/javascript" src="flowplayer-3.1.4.min.js"></script>
<!-- some minimal styling, can be removed -->
<link rel="stylesheet" type="text/css" href="style.css">
<!-- page title -->
<title>Minimal Flowplayer setup</title>
</head><body>
<div id="page">
<h1>Minimal Flowplayer setup</h1>
<p>View commented source code to get familiar with Flowplayer installation.</p>
<!-- this A tag is where your Flowplayer will be placed. it can be anywhere -->
<a
style="display:block;width:520px;height:330px"
id="player">
</a>
<!-- this will install flowplayer inside previous A- tag. -->
<script>
flowplayer("player", "plugin/flowplayer-3.1.5.swf",{
clip: {
//此处就是播放器读出的stream文件
url: 'http://www.malacity.net/streamer.php/iPhone.flv',
provider: 'lighttpd'
},
// streaming plugins are configured normally under the plugins node
plugins: {
lighttpd: {
url: 'flowplayer.pseudostreaming-3.1.3.swf'
}
}
});
</script>
<!--
after this line is purely informational stuff.
does not affect on Flowplayer functionality
-->
<p>
If you are running these examples <strong>locally</strong> and not on some webserver you must edit your
<a href="http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html">
Flash security settings</a>.
</p>
<p class="less">
Select "Edit locations" > "Add location" > "Browse for files" and select
flowplayer-x.x.x.swf you just downloaded.
</p>
<h2>Documentation</h2>
<p>
<a href="http://flowplayer.org/documentation/installation/index.html">Flowplayer installation</a>
</p>
<p>
<a href="http://flowplayer.org/documentation/configuration/index.html">Flowplayer configuration</a>
</p>
<p>
See this identical page on <a href="http://flowplayer.org/demos/example/index.htm">Flowplayer website</a>
</p>
</div>
</body></html>
具体的实例请参考我的链接
http://www.malacity.net/example/index.html
- 使用php文件读取视频stream并用flowplayer播放
- flowplayer视频播放插件
- 使用flowplayer给网站添加视频播放功能
- 【转】flowplayer视频播放插件
- web视频播放空间 flowplayer-3.2.16
- [开发笔记]-flowplayer视频播放插件
- flowPlayer播放flv视频基本设置
- web视频播放组件 flowplayer介绍
- web开源FlowPlayer视频播放器
- Flowplayer基于视频流的免费web视频播放器
- 在页面中使用Flowplayer播放器
- 在页面中使用Flowplayer播放器
- Flowplayer一款免费的WEB视频播放器
- Flowplayer-一款免费的WEB视频播放器
- Flowplayer-一款免费的WEB视频播放器
- JS 实现网页视频播放: vcastr22 、 flowplayer 、 jwplayer
- flowplayer 播放视频, 自动调整上下左右黑边大小
- Flowplayer-一款免费的WEB视频播放器
- 1
- Nvidia搞笑Intel:CPU vs GPU
- Gee... 啊?是吗?
- linux串口通信编程
- [英语阅读]拉美左翼集团将用虚币货币交易
- 使用php文件读取视频stream并用flowplayer播放
- 终身成就奖 lifetime achievement
- 2.5 罗马不是一夜建成的——从简单URL请求到整张地图
- 希望不是空欢喜——又进到google偷偷写了些东西
- 常见的三种职业教育投资
- MSG_NOSIGNAL
- AVR Bootloader编程
- wince下用DirectShow播放音频和视频
- 忆龙2009:CAMS做EAD在进行安全认证时出错“补丁检查失败” 的解决方法