我需要将Web服务器上选定的视频文件传输到客户端。我正在使用PHP脚本根据请求流式传输这些文件,但是我遇到了一个问题,如果我在本地网络上,它可以正常工作,但如果我是远程的,它会结束。例如。它似乎加载流,停止,加载更多,停止等,直到有足够的媒体可用于播放。我对这个东西很陌生,所以我需要一些关于如何解决这个问题的建议。带宽不应该是一个问题,所以我不知道发生了什么。我已经尝试了几个PHP的飘带,但所有的行为都差不多。我正在使用videojs在客户端中显示它。使用PHP从服务器流式传输视频
<?php
use vendor\videojswidget\VideoJsWidget;
$url = Yii::$app->urlManager->createUrl('/site/putvideo');
$currentVideo = '';
$script1 = "function playAnotherVideo(){
var source = document.getElementById('fileSelector');
var path = source.value;
$.ajax({
type: 'post',
data: {file: path},
url: '" .$url. "',
success: function(result){
var video = document.getElementById('videoPlayer');
video.src = result;
alert(result);
video.load();
},
error: function(){
alert('error');
}
});
}";
$this->registerJs($script1, yii\web\View::POS_END, 'my-options');
/* @var $this yii\web\View */
$this->title = 'View Vault Lecture Capture System';
?>
<div class="site-index" style="background-color: black; color: yellow;">
<div style="background-color: black;">
</br></br></br></br>
<h1 align="center">Welcome to the TEKVOX Lecture Capture System</h1>
</br></br></br></br>
</div>
<div class="body-content">
<div style="width: 100%; overflow: hidden;">
<div style="width: 50px; float: left;">
</br></br>
<label for="fileselector" style="margin-left: 4em; width: 10em;
font-weight: bold; color: #FFFF00;">Video_Files</label>
<select id="fileSelector" onchange="playAnotherVideo()" size="10em"
style="margin-left: 0em; color: #FFFF00; background-color: #000000;
border-color: #FFFFFF">
<?php
if ($handle = opendir('c:/users/admin/videos/')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != ".." &&
strtolower(substr($entry, strrpos($entry, '.') + 1)) ==
'mp4'){
echo "<option value='$entry'>" .$entry. "</option>";
}
}
closedir($handle);
}
?>
</select>
</div>
<span id="divplayer" style="margin-left: 20em;">
<?php
echo VideoJsWidget::widget([
'options' => [
'class' => '',
'id' => 'videoPlayer',
'poster' => "GreenX.png",
'controls' => true,
'preload' => 'none',
'width' => '800',
'height' => '450',
],
'tags' => [
'source' => [
['src' => '', 'type' => 'video/mp4'],
],
'track' => [
['kind' => 'captions', 'src' =>
'http://vjs.zencdn.net/vtt/captions.vtt', 'srclang' => 'en', 'label' =>
'English']
]
]
]);
?>
</span>
</div>
</div>
</br>
的getVideo.php代码:
<?php
include_once "videoStream.php";
$filename = $_GET['filename'];
if($filename == '')
return;
$file = "c:\\users\\admin\\videos\\" .$filename;
$stream = new VideoStream($file);
$stream->start();
>
目前我想出来的VideoStream.php类为:? VideoStream
什么也奇怪的是,玩家底部的酒吧似乎表明该视频已被缓冲,但玩家仍然口吃。不确定那是什么意思。
如果您分享您迄今为止所尝试的内容,包括示例代码,它会有所帮助。 – iangetz
你有没有看过http://nginx.org/en/docs/http/ngx_http_mp4_module.html和https://github.com/arut/nginx-rtmp-module,PHP并不是很适合你想要的东西,它增加了很多开销。 – hdezela