HTML5 live streaming

前端 未结 8 1232
北恋
北恋 2020-11-28 18:38

For school I need to set up an HTML5 live stream site. They have a flash stream-player they\'ve been using but now they want it to use HTML5 instead. How can I do this? I tr

8条回答
  •  醉梦人生
    2020-11-28 19:25

    Firstly you need to setup a media streaming server. You can use Wowza, red5 or nginx-rtmp-module. Read their documentation and setup on OS you want. All the engine are support HLS (Http Live Stream protocol that was developed by Apple). You should read documentation for config. Example with nginx-rtmp-module:

    rtmp {
        server {
            listen 1935; # Listen on standard RTMP port
            chunk_size 4000;
    
            application show {
                live on;
                # Turn on HLS
                hls on;
                hls_path /mnt/hls/;
                hls_fragment 3;
                hls_playlist_length 60;
                # disable consuming the stream from nginx as rtmp
                deny play all;
            }
        }
    } 
    
    server {
        listen 8080;
    
        location /hls {
            # Disable cache
            add_header Cache-Control no-cache;
    
            # CORS setup
            add_header 'Access-Control-Allow-Origin' '*' always;
            add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
            add_header 'Access-Control-Allow-Headers' 'Range';
    
            # allow CORS preflight requests
            if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Headers' 'Range';
                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/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
    
            root /mnt/;
        }
    }
    

    After server was setup and configuration successful. you must use some rtmp encoder software (OBS, wirecast ...) for start streaming like youtube or twitchtv.

    In client side (browser in your case) you can use Videojs or JWplayer to play video for end user. You can do something like below for Videojs:

    
    
    
        
        Live Streaming
        
        
    
    
    
    
    
    
    

    You don't need to add others plugin like flash (because we use HLS not rtmp). This player can work well cross browser with out flash.

提交回复
热议问题