zoukankan      html  css  js  c++  java
  • nginx+jwplayer配置flv/MP4点播系统, 视频拖动支持

    一 配置nginx

    1. 下载 nginx 最新版 http://nginx.org/

    2. 安装依赖库, 以ubuntu为例

    apt-get install libpcre3 libpcre3-dev libssl-dev openssl
    

    3. 编译nginx, 增加flv和MP4的支持

    /configure --with-http_flv_module --with-http_mp4_module  --with-http_ssl_module --with-debug
    

       编译时可以指定安装目录 --prefix=/path/to/install

       然后make install

    4. 测试是否支持seek(拖动, 快进)

        1) flv需要metadata数据才可以seek. 可以通过ffmpeg来查看flv视频是否有metadata数据. 

    > ffmpeg -i test.flv
    
    Input #0, flv, from 'test.flv':
      Metadata:
        metadatacreator : Yet Another Metadata Injector for FLV - Version 1.9
        hasKeyframes    : true
        hasVideo        : true
        hasAudio        : true
        hasMetadata     : true
        canSeekToEnd    : false
        datasize        : 23736525
        videosize       : 21784752
        audiosize       : 1923169
        lasttimestamp   : 157
        lastkeyframetimestamp: 153
        lastkeyframelocation: 23532906
    

      如果flv没有metadata数据. 可以通过yamdi来增加metadata数据, 这个工具windows和linux版本都有, 使用起来也很简单     

     yamdi -i sample.flv -o sample_with_metadata.flv  
    

      

         2) 把flv视频放在nginx 的html目录下. 然后通过curl或vlc测试拖动

         先修改下nginx的配置nginx.conf, 增加如下内容

            location ~ .flv$ {
                flv;
                limit_rate  250k;
            }
            location ~ .mp4$ {
                mp4;
                limit_rate  250k;
            }
    

      limit_rate是限速的意思, 因为是本地测试. 缓冲速度非常快. 如果不限速的话, 视频会立刻下载完成. 

    curl -I http://ip/test.flv
    Content-Length: 23739622
    
    curl -I http://ip/test.flv?start=2373
    Content-Length: 23727290
    

      两次的Content-Length不一样. 

      也可以通过vlc来播放http流. 都是界面点一点. 

    二 配置jwplayer

         网上的jwplayer的配置基本上是过时的. 误导我半天

      早期jwplayer里配置的streamer; type; provider; 这些参数在新版里已经没有, 或者不生效了. 

         jwplayer的support中关于seek的文章 http://support.jwplayer.com/customer/portal/articles/1430518-pseudo-streaming-in-flash 可能要翻墙才能看

    <div id="myElement">Loading the player...</div>
    
    <script type="text/javascript">
        jwplayer("myElement").setup({
            file:"http://ip/test.flv",
            image: "../image/webrtc.png",
            startparam: "start"
        });
    </script>
    

      关键是 startparam: "start". 没有这句的话. jwplayer是无法拖动视频的. MP4可以不需要这个startparam就可以拖动. 

      

        这个是jwplayer文档中关于startparam的参数说明. 

  • 相关阅读:
    记ByteCTF中的Node题
    Hooks中的useState
    IntersectionObserver对象
    Service Worker的应用
    使用 SpringBoot 构建一个RESTful API
    创业和技术有什么相通的“底层逻辑”?
    SpringBoot Profiles 多环境配置及切换
    SpringBoot Logback 日志配置
    应用分层和领域模型规约
    SpringBoot 整合 MyBatis,实现 CRUD 示例
  • 原文地址:https://www.cnblogs.com/lingdhox/p/4523885.html
Copyright © 2011-2022 走看看