首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用nginx和视频,js实现http实时流中质量选择器的问题

使用nginx和视频,js实现http实时流中质量选择器的问题
EN

Stack Overflow用户
提问于 2020-03-23 15:54:40
回答 1查看 2.1K关注 0票数 1

我最近开始使用nginx和video.js来建立一个活动流。问题:如果我使用视频as控制质量-级别和视频levels质量选择器作为video.js的加载项,他们应该自动插入一个基于下载播放列表的质量选择器和hls变体。但事实并非如此,它只是在激活自动选项的情况下添加了质量菜单。为什么HLS播放列表或播放机不访问变体并呈现正确的菜单?

版本:

视频:7.6.6

视频.质量.等级: 2.0.9

视频hls hls-质量-选择器: 1.1.1

下面是插入并启动播放机的代码:

代码语言:javascript
复制
this.videoJSplayer = videojs('video_player', {
      html5: {
        hls: {
          overrideNative:true,
          //withCredentials: true
       },
      controls: false,
      autoplay: false,
      preload: 'auto'
     }
this.videoJSplayer.src([{type:'application/x-mpegURL',src: URL + ".m3u8"}]);
      this.videoJSplayer.controls('true');
      this.videoJSplayer.play();
      this.isButtonVisible = false;
      this.videoJSplayer.hlsQualitySelector();

我的播放列表是这样的:

代码语言:javascript
复制
#EXT-X-STREAM-INF:PROGRAM-ID=1,CLOSED-CAPTIONS=NONE,BANDWIDTH=288000
test2_low.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,CLOSED-CAPTIONS=NONE,BANDWIDTH=2048000
test2_hd720.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,CLOSED-CAPTIONS=NONE,BANDWIDTH=4096000
test2_src.m3u8
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-23 17:32:28

解决方案相当简单:在播放列表中添加选项解析,如

代码语言:javascript
复制
hls_variant _src BANDWIDTH=4096000 RESOLUTION=1920x1080;

这将使插件能够正确地呈现选择器。没有这方面的手册。

配置现在如下所示

代码语言:javascript
复制
 worker_processes  1;
 events {
 worker_connections  1024;
 }
 # RTMP configuration
 
 rtmp {
 server {
 listen 1935; # Listen on standard RTMP port
 chunk_size 2048;
 # This application is to accept incoming stream

     application 00kSLqEV5a6LYVfFa1jG {
         live on; # Allows live input
 
                 exec ffmpeg -i rtmp://127.0.0.1/$app/$name
                     -c:v libx264 -c:a libfdk_aac -b:v 768k -b:a 96k -vf "scale=720:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://127.0.0.1/show/$name_low
                     -c:v libx264 -c:a libfdk_aac -b:v 1920k -b:a 128k -vf "scale=1280:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://127.0.0.1/show/$name_hd720
                     -c copy -f flv rtmp://127.0.0.1/show/$name_src;
 
         on_publish #server_auth;
 
     }
 
     application show {
         live on;
         # Turn on HLS
         hls on;
         hls_path #YOUR_PATH;
         hls_fragment 5;
         hls_playlist_length 30;
         # disable consuming the stream from nginx as rtmp
         allow publish 127.0.0.1;
         allow publish 139.18.13.224;
         deny publish all;
 
 
     hls_variant _low BANDWIDTH=288000 RESOLUTION=848x480;
     hls_variant _hd720 BANDWIDTH=2048000 RESOLUTION=1280x720;
     hls_variant _src BANDWIDTH=4096000 RESOLUTION=1920x1080;
 
    }
 
 }

 
 }
 
 http {
 sendfile off;
 tcp_nopush on;
 # aio on;

 directio 512;
 default_type application/octet-stream;
 include /usr/local/nginx/conf/mime.types;
 server {
     listen 80;
 
     location / {
         # Disable cache
         add_header 'Cache-Control' 'no-cache';

 # rewrite ^(/hls)/(\w+)$ $1/$200kSLqEV5a6LYVfFa1jG.m3u8;

         # CORS setup
         add_header 'Access-Control-Allow-Origin' '*' always;
         add_header 'Access-Control-Expose-Headers' 'Content-Length';
         add_header 'X-Frame-Options' 'DENY' always;
 
         # allow CORS preflight requests
         if ($request_method = 'OPTIONS') {
             add_header 'Access-Control-Allow-Origin' '*' always;
             add_header 'Access-Control-Max-Age' 1728000;
             add_header 'Content-Type' 'text/plain charset=UTF-8';
             add_header 'Content-Length' 0;
             return 204;
 
         }
 
         types {
             application/dash+xml mpd;
             application/vnd.apple.mpegurl m3u8;
             video/mp2t ts;
             text/html html;
             application/x-javascript js;
 
 # text/javascript js;

             text/css css;
         }
 
         index index.html;
 
     root #stream_root;
     location ~ \.php$ {
     fastcgi_split_path_info ^(.+\.php)(/.+)$;
     fastcgi_pass unix:/var/run/php-fpm.sock;
     set $path_info $fastcgi_path_info;
     fastcgi_param PATH_INFO $path_info;
     fastcgi_index index.php;
     include fastcgi.conf;
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
     fastcgi_param SCRIPT_NAME $fastcgi_script_name;
     fastcgi_param HTTP_PROXY "";
     proxy_set_header X-Forwarded-Uri /matomo;

 
 }
     }
 }
 
 }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60817032

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档