HTML5 live streaming

前端 未结 8 1191
北恋
北恋 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:08
    <object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"
                height="285" id="mediaPlayer" standby="Loading Microsoft Windows Media Player components..."
                type="application/x-oleobject" width="360" style="margin-bottom:30px;">
                <param name="fileName" value="mms://my_IP_Address:my_port" />
                <param name="animationatStart" value="true" />
                <param name="transparentatStart" value="true" />
                <param name="autoStart" value="true" />
                <param name="showControls" value="true" />
                <param name="loop" value="true" />
                <embed autosize="-1" autostart="true" bgcolor="darkblue" designtimesp="5311" displaysize="4"
                    height="285" id="mediaPlayer" loop="true" name="mediaPlayer" pluginspage="http://microsoft.com/windows/mediaplayer/en/download/"
                    showcontrols="true" showdisplay="0" showstatusbar="-1" showtracker="-1" src="mms://my_IP_Address:my_port"
                    type="application/x-mplayer2" videoborder3d="-1" width="360"></embed>
    </object>
    
    0 讨论(0)
  • You can use a fantastic library name Videojs. You will find more useful informations here. But with quick start you can do something like this:

    <link href="//vjs.zencdn.net/5.11/video-js.min.css" rel="stylesheet">
    <script src="//vjs.zencdn.net/5.11/video.min.js"></script>
    <video 
    id="Video" 
    class="video-js vjs-default-skin vjs-big-play-centered" 
    controls 
    preload="none" 
    width="auto" 
    height="auto" 
    poster="poster.jpg" 
    data-setup='{"techOrder": ["flash", "html5", "other supported tech"], "nativeControlsForTouch": true, "controlBar": { "muteToggle": false, "volumeControl": false, "timeDivider": false, "durationDisplay": false, "progressControl": false } }'
    >
    <source src="rtmp://{domain_server}/{publisher}" type='rtmp/mp4'/>
    </video>
    <script>
    var player = videojs('Video');
    player.play();
    </script>
    
    0 讨论(0)
  • 2020-11-28 19:20

    Right now it will only work in some browsers, and as far as I can see you haven't actually linked to a file, so that would explain why it is not playing.

    but as you want a live stream (which I have not tested with)

    check out Streaming via RTSP or RTP in HTML5

    and http://www.streamingmedia.com/Articles/Editorial/Featured-Articles/25-HTML5-Video-Resources-You-Might-Have-Missed-74010.aspx

    0 讨论(0)
  • 2020-11-28 19:22

    It is not possible to use the RTMP protocol in HTML 5, because the RTMP protocol is only used between the server and the flash player. So you can use the other streaming protocols for viewing the streaming videos in HTML 5.

    0 讨论(0)
  • 2020-11-28 19:25

    Live streaming in HTML5 is possible via the use of Media Source Extensions (MSE) - the relatively new W3C standard: https://www.w3.org/TR/media-source/ MSE is an an extension of HTML5 <video> tag; the javascript on webpage can fetch audio/video segments from the server and push them to MSE for playback. The fetching mechanism can be done via HTTP requests (MPEG-DASH) or via WebSockets. As of September 2016 all major browsers on all devices support MSE. iOS is the only exception.

    For high latency (5+ seconds) HTML5 live video streaming you can consider MPEG-DASH implementations by video.js or Wowza streaming engine.

    For low latency, near real-time HTML5 live video streaming, take a look at EvoStream media server, Unreal media server, and WebRTC.

    0 讨论(0)
  • 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:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Live Streaming</title>
        <link href="//vjs.zencdn.net/5.8/video-js.min.css" rel="stylesheet">
        <script src="//vjs.zencdn.net/5.8/video.min.js"></script>
    </head>
    <body>
    <video id="player" class="video-js vjs-default-skin" height="360" width="640" controls preload="none">
        <source src="http://localhost:8080/hls/stream.m3u8" type="application/x-mpegURL" />
    </video>
    <script>
        var player = videojs('#player');
    </script>
    </body>
    </html>
    

    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.

    0 讨论(0)
提交回复
热议问题