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 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等