doujue6196 2017-04-24 21:46
浏览 303

使用PHP从服务器流式传输视频

I need to stream selected video files on the web server to clients. I am using a PHP script to stream these files as requested, but I am running into an issue where if I am on a local net, it works fine, but if I am remote, it stutters. eg. it appears to load the stream, stop, load more, stop, etc. until enough media is available to play. I am new to this stuff, so I need some advise on how to overcome this issue. The bandwidth should not be a problem, so I am not sure what is going on. I have tried several php streamers, but all act pretty much the same. I am using videojs to display it within the client.

<?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>

The getVideo.php code:

<?php
include_once "videoStream.php";
$filename = $_GET['filename'];
if($filename == '')
    return;
$file = "c:\\users\\admin\\videos\\" .$filename;

 $stream = new VideoStream($file);
 $stream->start();

?>

The VideoStream.php class I am currently trying out is at: VideoStream

What is also strange is that the bar at the bottom of the player seems to indicate that the video is buffered, yet the player still stutters. Not sure what that means.

  • 写回答

1条回答 默认 最新

  • doulupian8725 2017-04-27 05:15
    关注

    The behaviour you describe is typical of video delivery over a low or intermittent bandwidth connection.

    The approaches to resolve this are typically quite sophisticated but on the server side built into readily available streaming servers, e.g: https://gstreamer.freedesktop.org

    You also may benefit from using a CDN like cloud front or Akami etc - these are basically designed to create copies of your content at the edge of the network to improve response times for users.

    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题