Code Monkey home page Code Monkey logo

videojs-contrib-hls's Introduction

Notice: this project will be deprecated and is succeeded by videojs-http-streaming. VHS supports HLS and DASH and is built into video.js 7, see the video.js 7 blog post

video.js HLS Source Handler

Build Status Slack Status Greenkeeper badge

Play back HLS with video.js, even where it's not natively supported.

Maintenance Status: Deprecated

Table of Contents generated with DocToc

Installation

NPM

To install videojs-contrib-hls with npm run

npm install --save videojs-contrib-hls

CDN

Select a version of HLS from cdnjs or jsDelivr

Releases

Download a release of videojs-contrib-hls

Manual Build

Download a copy of this git repository and then follow the steps in Building

Contributing

See CONTRIBUTING.md

Talk to us

Drop by our slack channel (#playback) on the Video.js slack.

Getting Started

Get a copy of videojs-contrib-hls and include it in your page along with video.js:

<video id=example-video width=600 height=300 class="video-js vjs-default-skin" controls>
  <source
     src="https://example.com/index.m3u8"
     type="application/x-mpegURL">
</video>
<script src="video.js"></script>
<script src="videojs-contrib-hls.min.js"></script>
<script>
var player = videojs('example-video');
player.play();
</script>

Check out our live example if you're having trouble.

Video.js 6

With Video.js 6, by default there is no flash support. Instead, flash support is provided through the videojs-flash plugin. If you are trying to use Video.js version 6 and want to include flash support, you must include videojs-flash on your page before including videojs-contrib-hls

<script src="https://unpkg.com/videojs-flash/dist/videojs-flash.js"></script>
<script src="https://unpkg.com/videojs-contrib-hls/dist/videojs-contrib-hls.js"></script>

Flash, and the videojs-flash plugin, are not required, but are recommended as a fallback option for browsers that don't have a native HLS player or support for Media Source Extensions.

Documentation

HTTP Live Streaming (HLS) has become a de-facto standard for streaming video on mobile devices thanks to its native support on iOS and Android. There are a number of reasons independent of platform to recommend the format, though:

  • Supports (client-driven) adaptive bitrate selection
  • Delivered over standard HTTP ports
  • Simple, text-based manifest format
  • No proprietary streaming servers required

Unfortunately, all the major desktop browsers except for Safari are missing HLS support. That leaves web developers in the unfortunate position of having to maintain alternate renditions of the same video and potentially having to forego HTML-based video entirely to provide the best desktop viewing experience.

This project addresses that situation by providing a polyfill for HLS on browsers that have support for Media Source Extensions, or failing that, support Flash. You can deploy a single HLS stream, code against the regular HTML5 video APIs, and create a fast, high-quality video experience across all the big web device categories.

Check out the full documentation for details on how HLS works and advanced configuration. A description of the adaptive switching behavior is available, too.

videojs-contrib-hls supports a bunch of HLS features. Here are some highlights:

  • video-on-demand and live playback modes
  • backup or redundant streams
  • mid-segment quality switching
  • AES-128 segment encryption
  • CEA-608 captions are automatically translated into standard HTML5 caption text tracks
  • In-Manifest WebVTT subtitles are automatically translated into standard HTML5 subtitle tracks
  • Timed ID3 Metadata is automatically translated into HTML5 metedata text tracks
  • Highly customizable adaptive bitrate selection
  • Automatic bandwidth tracking
  • Cross-domain credentials support with CORS
  • Tight integration with video.js and a philosophy of exposing as much as possible with standard HTML APIs
  • Stream with multiple audio tracks and switching to those audio tracks (see the docs folder) for info
  • Media content in fragmented MP4s instead of the MPEG2-TS container format.

Options

How to use

Initialization

You may pass in an options object to the hls source handler at player initialization. You can pass in options just like you would for other parts of video.js:

// html5 for html hls
videojs(video, {html5: {
  hls: {
    withCredentials: true
  }
}});

// or

// flash for flash hls
videojs(video, {flash: {
  hls: {
    withCredentials: true
  }
}});

// or

var options = {hls: {
  withCredentials: true
}};

videojs(video, {flash: options, html5: options});
Source

Some options, such as withCredentials can be passed in to hls during player.src

var player = videojs('some-video-id');

player.src({
  src: 'https://d2zihajmogu5jn.cloudfront.net/bipbop-advanced/bipbop_16x9_variant.m3u8',
  type: 'application/x-mpegURL',
  withCredentials: true
});

List

withCredentials
  • Type: boolean
  • can be used as a source option
  • can be used as an initialization option

When the withCredentials property is set to true, all XHR requests for manifests and segments would have withCredentials set to true as well. This enables storing and passing cookies from the server that the manifests and segments live on. This has some implications on CORS because when set, the Access-Control-Allow-Origin header cannot be set to *, also, the response headers require the addition of Access-Control-Allow-Credentials header which is set to true. See html5rocks's article for more info.

handleManifestRedirects
  • Type: boolean
  • Default: false
  • can be used as a source option
  • can be used as an initialization option

When the handleManifestRedirects property is set to true, manifest requests which are redirected will have their URL updated to the new URL for future requests.

useCueTags
  • Type: boolean
  • can be used as an initialization option

When the useCueTags property is set to true, a text track is created with label 'ad-cues' and kind 'metadata'. The track is then added to player.textTracks(). Changes in active cue may be tracked by following the Video.js cue points API for text tracks. For example:

let textTracks = player.textTracks();
let cuesTrack;

for (let i = 0; i < textTracks.length; i++) {
  if (textTracks[i].label === 'ad-cues') {
    cuesTrack = textTracks[i];
  }
}

cuesTrack.addEventListener('cuechange', function() {
  let activeCues = cuesTrack.activeCues;

  for (let i = 0; i < activeCues.length; i++) {
    let activeCue = activeCues[i];

    console.log('Cue runs from ' + activeCue.startTime +
                ' to ' + activeCue.endTime);
  }
});
overrideNative
  • Type: boolean
  • can be used as an initialization option

Try to use videojs-contrib-hls even on platforms that provide some level of HLS support natively. There are a number of platforms that technically play back HLS content but aren't very reliable or are missing features like CEA-608 captions support. When overrideNative is true, if the platform supports Media Source Extensions videojs-contrib-hls will take over HLS playback to provide a more consistent experience.

NOTE: If you use this option, you must also set videojs.options.html5.nativeAudioTracks and videojs.options.html5.nativeVideoTracks to false. videojs-contrib-hls relies on audio and video tracks to play streams with alternate audio and requires additional capabilities only supported by non-native tracks in video.js.

blacklistDuration
  • Type: number
  • can be used as an initialization option

When the blacklistDuration property is set to a time duration in seconds, if a playlist is blacklisted, it will be blacklisted for a period of that customized duration. This enables the blacklist duration to be configured by the user.

bandwidth
  • Type: number
  • can be used as an initialization option

When the bandwidth property is set (bits per second), it will be used in the calculation for initial playlist selection, before more bandwidth information is seen by the player.

enableLowInitialPlaylist
  • Type: boolean
  • can be used as an initialization option

When enableLowInitialPlaylist is set to true, it will be used to select the lowest bitrate playlist initially. This helps to decrease playback start time. This setting is false by default.

Runtime Properties

Runtime properties are attached to the tech object when HLS is in use. You can get a reference to the HLS source handler like this:

var hls = player.tech({ IWillNotUseThisInPlugins: true }).hls;

If you were thinking about modifying runtime properties in a video.js plugin, we'd recommend you avoid it. Your plugin won't work with videos that don't use videojs-contrib-hls and the best plugins work across all the media types that video.js supports. If you're deploying videojs-contrib-hls on your own website and want to make a couple tweaks though, go for it!

hls.playlists.master

Type: object

An object representing the parsed master playlist. If a media playlist is loaded directly, a master playlist with only one entry will be created.

hls.playlists.media

Type: function

A function that can be used to retrieve or modify the currently active media playlist. The active media playlist is referred to when additional video data needs to be downloaded. Calling this function with no arguments returns the parsed playlist object for the active media playlist. Calling this function with a playlist object from the master playlist or a URI string as specified in the master playlist will kick off an asynchronous load of the specified media playlist. Once it has been retreived, it will become the active media playlist.

hls.segmentXhrTime

Type: number

The number of milliseconds it took to download the last media segment. This value is updated after each segment download completes.

hls.bandwidth

Type: number

The number of bits downloaded per second in the last segment download. This value is used by the default implementation of selectPlaylist to select an appropriate bitrate to play.

Before the first video segment has been downloaded, it's hard to estimate bandwidth accurately. The HLS tech uses a heuristic based on the playlist download times to do this estimation by default. If you have a more accurate source of bandwidth information, you can override this value as soon as the HLS tech has loaded to provide an initial bandwidth estimate.

hls.bytesReceived

Type: number

The total number of content bytes downloaded by the HLS tech.

hls.selectPlaylist

Type: function

A function that returns the media playlist object to use to download the next segment. It is invoked by the tech immediately before a new segment is downloaded. You can override this function to provide your adaptive streaming logic. You must, however, be sure to return a valid media playlist object that is present in player.hls.master.

Overridding this function with your own is very powerful but is overkill for many purposes. Most of the time, you should use the much simpler function below to selectively enable or disable a playlist from the adaptive streaming logic.

hls.representations

Type: function

It is recommended to include the videojs-contrib-quality-levels plugin to your page so that videojs-contrib-hls will automatically populate the QualityLevelList exposed on the player by the plugin. You can access this list by calling player.qualityLevels(). See the videojs-contrib-quality-levels project page for more information on how to use the api.

Example, only enabling representations with a width greater than or equal to 720:

var qualityLevels = player.qualityLevels();

for (var i = 0; i < qualityLevels.length; i++) {
  var quality = qualityLevels[i];
  if (quality.width >= 720) {
    quality.enabled = true;
  } else {
    quality.enabled = false;
  }
}

If including videojs-contrib-quality-levels is not an option, you can use the representations api. To get all of the available representations, call the representations() method on player.hls. This will return a list of plain objects, each with width, height, bandwidth, and id properties, and an enabled() method.

player.hls.representations();

To see whether the representation is enabled or disabled, call its enabled() method with no arguments. To set whether it is enabled/disabled, call its enabled() method and pass in a boolean value. Calling <representation>.enabled(true) will allow the adaptive bitrate algorithm to select the representation while calling <representation>.enabled(false) will disallow any selection of that representation.

Example, only enabling representations with a width greater than or equal to 720:

player.hls.representations().forEach(function(rep) {
  if (rep.width >= 720) {
    rep.enabled(true);
  } else {
    rep.enabled(false);
  }
});

hls.xhr

Type: function

The xhr function that is used by HLS internally is exposed on the per- player hls object. While it is possible, we do not recommend replacing the function with your own implementation. Instead, the xhr provides the ability to specify a beforeRequest function that will be called with an object containing the options that will be used to create the xhr request.

Example:

player.hls.xhr.beforeRequest = function(options) {
  options.uri = options.uri.replace('example.com', 'foo.com');

  return options;
};

The global videojs.Hls also exposes an xhr property. Specifying a beforeRequest function on that will allow you to intercept the options for all requests in every player on a page. For consistency across browsers the video source should be set at runtime once the video player is ready.

Example

videojs.Hls.xhr.beforeRequest = function(options) {
  /*
   * Modifications to requests that will affect every player.
   */

  return options;
};

var player = videojs('video-player-id');
player.ready(function() {
  this.src({
    src: 'https://d2zihajmogu5jn.cloudfront.net/bipbop-advanced/bipbop_16x9_variant.m3u8',
    type: 'application/x-mpegURL',
  });
});

For information on the type of options that you can modify see the documentation at https://github.com/Raynos/xhr.

Events

Standard HTML video events are handled by video.js automatically and are triggered on the player object.

loadedmetadata

Fired after the first segment is downloaded for a playlist. This will not happen until playback if video.js's metadata setting is none

HLS Usage Events

Usage tracking events are fired when we detect a certain HLS feature, encoding setting, or API is used. These can be helpful for analytics, and to pinpoint the cause of HLS errors. For instance, if errors are being fired in tandem with a usage event indicating that the player was playing an AES encrypted stream, then we have a possible avenue to explore when debugging the error.

Note that although these usage events are listed below, they may change at any time without a major version change.

HLS usage events are triggered on the tech with the exception of the 3 hls-reload-error events, which are triggered on the player.

Presence Stats

Each of the following usage events are fired once per source if (and when) detected:

Name Description
hls-webvtt master manifest has at least one segmented WebVTT playlist
hls-aes a playlist is AES encrypted
hls-fmp4 a playlist used fMP4 segments
hls-demuxed audio and video are demuxed by default
hls-alternate-audio alternate audio available in the master manifest
hls-playlist-cue-tags a playlist used cue tags (see useCueTags(#usecuetags) for details)

Use Stats

Each of the following usage events are fired per use:

Name Description
hls-gap-skip player skipped a gap in the buffer
hls-player-access player.hls was accessed
hls-audio-change a user selected an alternate audio stream
hls-rendition-disabled a rendition was disabled
hls-rendition-enabled a rendition was enabled
hls-rendition-blacklisted a rendition was blacklisted
hls-timestamp-offset a timestamp offset was set in HLS (can identify discontinuities)
hls-unknown-waiting the player stopped for an unknown reason and we seeked to current time try to address it
hls-live-resync playback fell off the back of a live playlist and we resynced to the live point
hls-video-underflow we seeked to current time to address video underflow
hls-error-reload-initialized the reloadSourceOnError plugin was initialized
hls-error-reload the reloadSourceOnError plugin reloaded a source
hls-error-reload-canceled an error occurred too soon after the last reload, so we didn't reload again (to prevent error loops)

In-Band Metadata

The HLS tech supports timed metadata embedded as ID3 tags. When a stream is encountered with embedded metadata, an in-band metadata text track will automatically be created and populated with cues as they are encountered in the stream. UTF-8 encoded TXXX and WXXX ID3 frames are mapped to cue points and their values set as the cue text. Cues are created for all other frame types and the data is attached to the generated cue:

cue.value.data

There are lots of guides and references to using text tracks around the web.

Segment Metadata

You can get metadata about the segments currently in the buffer by using the segment-metadata text track. You can get the metadata of the currently rendered segment by looking at the track's activeCues array. The metadata will be attached to the cue.value property and will have this structure

cue.value = {
  byteLength, // The size of the segment in bytes
  bandwidth, // The peak bitrate reported by the segment's playlist
  resolution, // The resolution reported by the segment's playlist
  codecs, // The codecs reported by the segment's playlist
  uri, // The Segment uri
  timeline, // Timeline of the segment for detecting discontinuities
  playlist, // The Playlist uri
  start, // Segment start time
  end // Segment end time
};

Example: Detect when a change in quality is rendered on screen

let tracks = player.textTracks();
let segmentMetadataTrack;

for (let i = 0; i < tracks.length; i++) {
  if (tracks[i].label === 'segment-metadata') {
    segmentMetadataTrack = tracks[i];
  }
}

let previousPlaylist;

if (segmentMetadataTrack) {
  segmentMetadataTrack.on('cuechange', function() {
    let activeCue = segmentMetadataTrack.activeCues[0];

    if (activeCue) {
      if (previousPlaylist !== activeCue.value.playlist) {
        console.log('Switched from rendition ' + previousPlaylist +
                    ' to rendition ' + activeCue.value.playlist);
      }
      previousPlaylist = activeCue.value.playlist;
    }
  });
}

Hosting Considerations

Unlike a native HLS implementation, the HLS tech has to comply with the browser's security policies. That means that all the files that make up the stream must be served from the same domain as the page hosting the video player or from a server that has appropriate CORS headers configured. Easy instructions are available for popular webservers and most CDNs should have no trouble turning CORS on for your account.

Known Issues

Issues that are currenty know about with workarounds. If you want to help find a solution that would be appreciated!

IE10 and Below

As of version 5.0.0, IE10 and below are no longer supported.

Fragmented MP4 Support

Edge has native support for HLS but only in the MPEG2-TS container. If you attempt to play an HLS stream with fragmented MP4 segments, Edge will stall. Fragmented MP4s are only supported on browser that have Media Source Extensions available.

Testing

For testing, you run npm run test. This will run tests using any of the browsers that karma-detect-browsers detects on your machine.

Release History

Check out the changelog for a summary of each release.

Building

To build a copy of videojs-contrib-hls run the following commands

git clone https://github.com/videojs/videojs-contrib-hls
cd videojs-contrib-hls
npm i
npm run build

videojs-contrib-hls will have created all of the files for using it in a dist folder

Development

Tools

Commands

All commands for development are listed in the package.json file and are run using

npm run <command>

videojs-contrib-hls's People

Contributors

bc-bbay avatar bcdmlap avatar bclwhitaker avatar benjaminp avatar brandonocasey avatar chikathreesix avatar dmlap avatar forbesjo avatar gesinger avatar gkatsev avatar greenkeeper[bot] avatar heff avatar imbcmdth avatar katrinae avatar marguinbc avatar mikrohard avatar mjneil avatar mrocajr avatar paruls avatar publicparadise avatar quarkus avatar rajkosto avatar ruchigupta19 avatar shahlabs avatar squarebracket avatar stevemayhew avatar t2y avatar tom-johnson avatar tomjohnson916 avatar zhuangs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

videojs-contrib-hls's Issues

Remove Buffer Management from Player API Methods

I'm wondering if it could be possible to disentangle buffer management from player API methods like setCurretTime() and play().

For instance, we're currently using setCurrentTime to empty and refill the buffer on a seek. It seems like instead we could have something external monitoring events, like seeking, and updating the buffer independently.

Are there any specific blockers/challenges we might run into if we purse that direction, including for other API methods?

Part of the thought here is a deeper integration of Video.js with media source extensions, but either way I think this could help modularize some things.

My current thought is introducing something like a "source handler" into video.js, that could register itself with the existing html5 or Flash tech. If the source handler's specific format was provided, the tech would pass it the source and a reference to the playback element/object. From there the tech would continue to operate with the playback object as usual, and the source handler would interact directly with the playback object, not the tech, filling its buffer as needed.

That seems like the ideal scenario at least, and removes the need for HLS to subclass a tech.

Any thoughts on that specifically? @dmlap

Unusual CPU activity during live stream

Around 9140ms, append() starts taking > 16ms. It also appears that vjs_endOfStream is a significant proportion of that time. That is surprising because vjs_endOfStream should only be called when the playlist is complete and the last segment has been delivered to the SourceBuffer.

Exported CPU profile, Chrome 34/OS X

HLS playlists without '\n' newline at the end of the file are played as LIVE

Hi Guys,
Browser: Chrome latest

...
#EXTINF:9.9,
video-hls-3500-8.ts
#EXTINF:7.7,
video-hls-3500-9.ts
#EXT-X-ENDLIST

This is a properly terminated playlist, but it is missing a newline character at the end. The plugin detects it as LIVE playlist as if it were not terminated with #EXT-X-ENDLIST

https://s3-us-west-2.amazonaws.com/udropr-content-dev/user-0Sergey/test13/video-hls-3500/playlist-3500.m3u8

I am not sure it is a correct playlist according to the spec, but Safari and iOS are both able to play it correctly.

Getting HLS Chunk Information

Continuation of videojs/video.js#1287.

From looking at the docs, there doesn't appear to be a nice way to listen for when a .ts chunk starts downloading, stops downloading, and getting the duration of the chunk (you could look at target duration, but that isn't a sure thing).

If this data is present, how would I access it? Could there be an events added for when chunks start and finish downloading along with extra information such as duration of the chunk?

Example.html does not work with firefox or Chrome

I've tried the example with Chrome 34.0.1847.3 dev 27.0.1 of Firefox on OS X, and in both cases it just shows the player and controls with no video. It works fine in Safari but it did that already.

HLS Range Error in flv-tag.js

I get this alot when trying to stream a video, chrome and Firefox. it appears it tries to download the same ts file over and over and then keeps error-ing out on the index.

Uncaught RangeError: Offset is outside the bounds of the DataView flv-tag.js:293
finalize flv-tag.js:293
self.getNextTag segment-parser.js:143
segmentXhr.onreadystatechange videojs-hls.js:591

Any one have any suggestions?

broken seek

hi,
this may be a matter of bad configuration but, in my setup video plays but when i try to seek i get this error:
VIDEOJS:
TypeError {stack: (...), message: "undefined is not a function"}
with following stack:
Uncaught TypeError: undefined is not a function videojs.hls.min.js:3
a.hls.setCurrentTime videojs.hls.min.js:3
V video.js:58
t.currentTime video.js:59
t.Kb video.js:80
t.Wa video.js:36
t.Wa video.js:80
e video.js:12
e.X.e.X video.js:5

videojs is 4.6.4
videojs.hls 0.8.2

Support Audio Only track in plugin

The issue listed below has not been fixed in the videojs master branch or the feature branch for HLS. I'm re-creating it here because the apple settings require the audio only track, but this breaks the Chrome / Flash fallback. I'm hoping it's already fixed, and apologize if so but github removed the messaging functionality.

videojs/video.js#813

Flash crashes when running in the background

Moved from videojs/video-js-swf#95:

When playing a HLS stream with the Flash player (current master 8a98910) in a tab which is currently not the active tab, the playback will pause after some time. If you go to the tab, playback will resume. If you don't, playback will not resume, and the whole tab will crash a while later.

After playback has paused, my Activity Monitor shows a Google Chrome Helper process sponging up memory at about 10 megabytes per second, up until it consumes ~1.1GB and then the tab crashes.

It always happens at the same parts of the stream. The stream is a m3u8 playlist of finite length, with some #EXT-X-DISCONTINUITY flags and gaps in the timestamps between the video segments.

It does not seem to happen when the Flash player plays media that is not HLS.

I'm using Google Chrome 35.0.1916.114 on OSX and Flash (Adobe) 13.0.0.214.

@mkilling: moved this to the HLS repo. Do you believe this would occur with any HLS stream or is it something specific about the streams you're testing with?

Missing HLS test files in example.html

@dmlap @raytiley Could you provide the following folder files (../node_modules/**) download address for test?

because the following codes need those files:
<\script src="../node_modules/sinon/lib/sinon.js">
<\script src="../node_modules/sinon/lib/sinon/util/event.js">
<\script src="../node_modules/sinon/lib/sinon/util/fake_xml_http_request.js">
<\script src="../node_modules/sinon/lib/sinon/util/xhr_ie.js">
<\script src="../node_modules/sinon/lib/sinon/util/fake_timers.js">

<\link rel="stylesheet" href="../libs/qunit/qunit.css" media="screen">
<\script src="../libs/qunit/qunit.js">

<\script src="../node_modules/video.js/dist/video-js/video.js">
<\script src="../node_modules/videojs-contrib-media-sources/src/videojs-media-sources.js">

HLS doesn't work in Firefox

HLS with videojs does not work in Firefox (tried in v29.0.1)

Setup:

<video id="video_player" class="video-js vjs-default-skin" controls preload="auto" width="620px" height="465px" poster="https://thumbnail">
    <source type="application/x-mpegURL" src="http://s3.amazonaws.com/my_bucket/my_playlist.m3u8">
</video>
videojs("video_player", { playbackRates: [1, 1.5, 2, 3], techOrder: ['hls', 'html5', 'flash'] })

Console output:

Specified "type" attribute of "application/x-mpegURL" is not supported. Load of media resource http://s3.amazonaws.com/my_bucket/my_playlist.m3u8 failed.
All candidate resources failed to load. Media load paused.
"VIDEOJS:" "ERROR:" "(CODE:4 MEDIA_ERR_SRC_NOT_SUPPORTED)" "No compatible source was found for this video." {code: 4, message: "No compatible source was found for this video."}
All candidate resources failed to load. Media load paused.

I don't see the Flash fallback .SWF being requested anywhere.

Status Report?

Hey guys!

Any chance of getting a situation report on this project? The README says "Coming Soon," but doesn't give much indication of when "Soon" is. :) The links to the Production and Developer builds are broken, too.

Since this commit: videojs/video.js#748 - do we even need to use this 'contrib' project at all?

In the mean time, we've been having success with: https://github.com/mangui/HLSprovider and this https://github.com/denivip/osmf-hls-plugin but would obviously prefer to use Video.js

If we can get a definitive answer about the status of this, I'll be happy to write a tutorial and to update the README.

use alternative swf with HLS into?

have you taken a look at some hls implementations for flash like the one on grindplayer or the marvellous video-js-swf from mangui for hls. It can be a really interesting alternative at the hls parsing/buffering by JS?

Moreover it immediately solves many incompatibilities

Maybe your position is the opposite and I just want to know if it is a plan in the future for you or not.

For me adding your project, the swf of mangui and a resolution selector and we can create the number one video player.

segment-parser.js, L135: The property 'readBytes' does not exist on value of type 'Uint8Array'.

When compiled with Microsoft's Typescript compiler 1.0.1 this line in parseSegmentBinaryData() of segment-parser.js throws an error:

// error TS2094: The property 'readBytes' does not exist on value of type 'Uint8Array'.
streamBuffer.readBytes(data, data.length, streamBuffer.length);

I suspect this line should read:

streamBuffer.set(data, streamBuffer.length);

Please let me know if you need more information.

Bernd Paradies, Adobe Systems Inc.

segment-parser.js, 3 bugs in getFlvHeader()

When compiled with Microsoft's Typescript compiler 1.0.1 these three lines in getFlvHeader() of segment-parser.js throw three errors:

result = new Uint8Array(headBytes.byteLength + metadata.byteLength);
result.set(head);
result.set(head.bytesLength, metadata.finalize());

The three errors are:

// error TS2094: The property 'byteLength' does not exist on value of type 'FlvTag'.
result = new Uint8Array(headBytes.byteLength + metadata.byteLength);
// error TS2082: Supplied parameters do not match any signature of call target:
// Type 'DataView' is missing property 'BYTES_PER_ELEMENT' from type 'Uint8Array'.
result.set(head);
// error TS2082: Supplied parameters do not match any signature of call target:
// Could not apply type 'number' to argument 2 which is of type 'FlvTag'.
// error TS2094: The property 'bytesLength' does not exist on value of type 'DataView'.
result.set(head.bytesLength, metadata.finalize());

The last error is the most severe one, because that expression gets evaluated to

result.set(NaN, NaN);

which browsers happily ignore (see Keep On Truckin').

I believe those lines of code should probably read:

      // write out the duration metadata tag
      metadata = new FlvTag(FlvTag.METADATA_TAG);
      metadata.pts = metadata.dts = 0;
      metadata.writeMetaDataDouble("duration", duration);
      metadataLength = metadata.finalize().length;
      result = new Uint8Array(headBytes.byteLength + metadataLength);
      result.set(headBytes);
      result.set(head.byteLength, metadataLength);

Getting Bitrate of Content.

Is there currently a way to get the bitrate (or download speed) of the content that is currently playing?

video.js 4.7.0 is incompatible with videojs-contrib-hls

I was upgrading a site to video.js 4.7.0 and noticed that seeking in HLS is broken with the newer version of video.js. It seems that this is caused by some change in the Flash component because reverting to the video-js.swf from 4.6.4 makes it work again.

Flash player progress bar skips forward when encountering timestamp gaps

I'm doing HLS streaming with a finite playlist of segments.

The video segments have strictly monotonically increasing timestamps, but there might be timestamp gaps (of indefinite duration) between the segments. When encountering these gaps, the Flash player's progress bar skips forward: E.g. if there is a 30 second gap, the player's progress bar skips forward by 30 seconds.

The displayed total duration of the video does not increase accordingly. This causes funny rendering of the progress bar towards the end of the video playback:

screen shot 2014-05-25 at 13 17 54

It also happens when I explicitly specify #EXT-X-DISCONTINUITY for the gaps.

Both Safari's built-in HLS player's as well as JWPlayer's progress bars do not skip forward when encountering timestamp gaps, even when #EXT-X-DISCONTINUITY is not specified.

MIME types should be case insensitive

The valid mime-types we accept should be case insensitive for the type/subtype params per:
http://tools.ietf.org/html/rfc2045. Currently we fail if a valid type is used, but it doesn't match the case sensitivity we are expecting.

[4:55 PM] Tom Ruggles: yup. For shame.
;)
I changed it from "type": "application/x-mpegUrl" to "type": "application/x-mpegURL" and it worked.

videojs-hls.js: incoherent usage of internal and external APIs.

Microsoft's Typescript compiler 1.0.1 finds 4 errors in videojs-hls.js.
The following three places are not severe errors. But they still show incorrect usage of internal and external APIs:

1) player.hls.setCurrentTime is a void method

player.hls.setCurrentTime = function(currentTime) {
      if (!(this.playlists && this.playlists.media())) {
        // return immediately if the metadata is not ready yet
        return 0;
      }

player.hls.setCurrentTime seems to be a void function and should read:

player.hls.setCurrentTime = function(currentTime) {
      if (!(this.playlists && this.playlists.media())) {
        // return immediately if the metadata is not ready yet
        return;
      }

2) fillbuffer expects offsets, not events

From what I understand fillbuffer expects offsets:

/**
     * Determines whether there is enough video data currently in the buffer
     * and downloads a new segment if the buffered time is less than the goal.
     * @param offset (optional) {number} the offset into the downloaded segment
     * to seek to, in milliseconds
     */
    fillBuffer = function(offset) {

But registering fillbuffer directly as in drainBuffer() exposes fillbuffer to calls with Event objects instead of offsets:

player.on('timeupdate', fillBuffer);

Instead I suggest using a wrapper:

player.on('timeupdate', function(e) { fillBuffer(); });

3) SourceBuffer.appendBuffer only takes one parameter.

The second parameter is being ignored:

player.hls.sourceBuffer.appendBuffer(tags[i].bytes, player);

I suggest removing 'player':

player.hls.sourceBuffer.appendBuffer(tags[i].bytes);

4) Checking against videojs.MediaSource

This code is technically correct

videojs.Hls.isSupported = function() {
  return !videojs.Hls.supportsNativeHls &&
    videojs.Flash.isSupported() &&
    videojs.MediaSource;
};

But I find this version cleaner:

videojs.Hls.isSupported = function() {
  return !videojs.Hls.supportsNativeHls &&
    videojs.Flash.isSupported() &&
    !!videojs.MediaSource;
};

Please let me know if you need more information.

Bernd Paradies, Adobe Systems Inc.

originalSegment is undefined at first segment end

When playing a live stream using HLS, the stream plays for around 10 seconds before pausing. The streams are fine in HTML5 players.

My console is filled up with this message:

TypeError: originalSegment is undefined    videojs.hls.js:136

This is Fedora 19, Firefox 30. I'll try to get an example to show, when work permits.

HLS video doesn't fire 'ended' event

Hi Guys,
I have a playlist with variable durations of each segment. Each segment's duration is reported in seconds to a 10th decimal point precision, but there is obviously a rounding error. When HLS plugin plays this movie it is not able to detect the end of the movie. Safari and iOS are both able to correctly play this playlist.

#EXTM3U
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-TARGETDURATION:11
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:10.9,
video-hls-3500-0.ts
#EXTINF:9.9,
video-hls-3500-1.ts
#EXTINF:9.9,
video-hls-3500-2.ts
#EXTINF:9.9,
video-hls-3500-3.ts
#EXTINF:9.6,
video-hls-3500-4.ts
#EXTINF:9.7,
video-hls-3500-5.ts
#EXTINF:9.9,
video-hls-3500-6.ts
#EXTINF:9.8,
video-hls-3500-7.ts
#EXTINF:9.9,
video-hls-3500-8.ts
#EXTINF:7.7,
video-hls-3500-9.ts
#EXT-X-ENDLIST

https://s3-us-west-2.amazonaws.com/udropr-content-dev/user-0Sergey/test13/video-hls-3500/playlist-3500.m3u8

Thank you!

vjs-has-started not updated with 4.6

Hi,
it seems that some refactoring between 4.5 and 4.6 broke the vjs-has-started / related callbacks. I can click the button and the hls video plays, but the css class is not applied.
if i manually hack it in the dom, the button disappears and the controlbar appreas correctly.

MSE HLS?

Just hoping to get an idea of how far we are from supporting HLS through MSE. That may be something I try to help out with here soon if it's needed.

We talked about this briefly before, but one thing I'm wondering is if we'll end up with two techs, hls-mse and hls-flash, since the current HLS extends vjs.Flash, and the easiest way to add MSE HLS would seem to be to extend vjs.Html5, like was done in vjs.Dashjs.

m3u8-parser.js, L140: parseFloat only accepts one parameter

When compiled with Microsoft's Typescript compiler 1.0.1 this line in m3u8-parser.js throws an error, pointing out that parseFloat() only accepts one parameter:

      if (match[1]) {
        event.duration = parseFloat(match[1], 10);
      }

The line above should read:

      if (match[1]) {
        event.duration = parseFloat(match[1]);
      }

Please let me know if you need more information.

Bernd Paradies, Adobe Systems Inc.

Inconsistencies between videojs

Am I missing something or there are inconsistencies between videojs-contrib-hls and videojs?

I tried to follow the example from the readme and I get a lot of errors like, can't find: window.videojs.util.mergeOptions. Looking at videojs I so there is a videojs.obj.merge, maybe it was renamed?

Also I have a http://domain.com/stream.ts format url, from a media streaming server, is there anyway to play that directly without a .m3u8 file?

paused videos stop buffering

The fillBuffer function is called on the timeupdate event. Since timeupdate doesn't fire when the video is paused, pausing causes the player to stop further buffering of data.

Initializing source on VideoJS player later throws an error

If the source is not specified during player initialization but later during plugin initialization, we get the below error.

VIDEOJS: Video.js: currentTime unavailable on Html5 playback technology element. 
TypeError {stack: (...), message: "Cannot read property 'currentTime' of null"}

example.html:

<script>
    videojs.options.flash.swf = 'node_modules/video.js/dist/video-js/video-js.swf';
    // initialize the player
    var player = videojs('video', {
      techOrder: ['html5', 'flash', 'hls']
    });
    // fire the plugin
    player.ready(function() {
      player.onceux();
    });
  </script>

oneux.js :

onceux = function(options) {
    var 
      settings = videojs.util.mergeOptions(defaults, options),
      player = this;

    var media_hls = 'http://once.unicornmedia.com/now/ctadaptive/m3u8/77128e82-3acd-4064-ab71-f6de437aba5d/da63d706-dae8-4110-9035-e7e79b753ed0/f1a96e7e-d5b8-4737-a527-45c0f79702d9/content.m3u8';
    // set the player src to onceux url
    player.src([
      { type: "application/x-mpegURL", src: media_hls }
    ]);
   videojs.plugin('onceux', onceux);
  };

Problem loading HLS link

we are developing an android app for our OTT platform.We have our streams in HLS format both(Live and VOD).So we are trying to embedd video.js in our website for playback our streams.The streams are encoded in multibitrate for adaptive bitrate streaming.When we tried it in our pc browsers its playing fine but the streams are not being switched.It only play only a single bitrate stream.but it work fine on android and ios.

whats the reason for this error..??

Try other sources if HLS fails

Since the HLS plugin requires CORS headers on the HLS host, it sometimes fails. In these cases, it would be best if Video.js tried the next source rather than just failing.

VideoJSTechDetectorStatic._isSafari() returns true in Chrome 36.0.1985.125 on OSX

This expression returns true in Chrome 36.0.1985.125 on OSX:

VideoJSTechDetectorStatic.prototype._isSafari = function () {
            return (/Safari/i).test(videojs.USER_AGENT);
        };

The user agent string in in Chrome 36.0.1985.125 on OSX is:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36

The better implementation of _isSafari() is suggested in
http://stackoverflow.com/questions/7944460/detect-safari-browser:

VideoJSTechDetectorStatic.prototype._isSafari = function () {
        var ua = videojs.USER_AGENT.toLowerCase();
        if( ua.indexOf('safari') !=-1 && ua.indexOf('chrome') == -1 )
        {
            return true;
        }
        return false;
   };

Master playlist misidentified

This playlist is interpreted by the parser as a media playlist. It should be parsed as a master playlist.

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=150000,CODECS="mp4a.40.5,avc1.42c00d",RESOLUTION=400x224
http://api35-phx.unicornmedia.com/now/od/m3u8/XXX/content.m3u8?visitguid=6c2aa0d0-0338-450f-b26c-3161332c6aa7&segmentlength=10&protocolversion=3
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1200000,CODECS="mp4a.40.5,avc1.64001f",RESOLUTION=864x480
http://api35-phx.unicornmedia.com/now/od/m3u8/XXX/content.m3u8?visitguid=6c2aa0d0-0338-450f-b26c-3161332c6aa7&segmentlength=10&protocolversion=3
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=880000,CODECS="mp4a.40.5,avc1.42c01e",RESOLUTION=400x224
http://api35-phx.unicornmedia.com/now/od/m3u8/guid-stuff/content.m3u8?visitguid=6c2aa0d0-0338-450f-b26c-3161332c6aa7&segmentlength=10&protocolversion=3
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=660000,CODECS="mp4a.40.5,avc1.42c00d",RESOLUTION=400x224
http://api35-phx.unicornmedia.com/now/od/m3u8/guid-stuff/content.m3u8?visitguid=6c2aa0d0-0338-450f-b26c-3161332c6aa7&segmentlength=10&protocolversion=3
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=440000,CODECS="mp4a.40.5,avc1.42c00d",RESOLUTION=400x224
http://api35-phx.unicornmedia.com/now/od/m3u8/guid-stuff/content.m3u8?visitguid=6c2aa0d0-0338-450f-b26c-3161332c6aa7&segmentlength=10&protocolversion=3
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=340000,CODECS="mp4a.40.5,avc1.42c00d",RESOLUTION=400x224
http://api35-phx.unicornmedia.com/now/od/m3u8/guid-stuff/content.m3u8?visitguid=6c2aa0d0-0338-450f-b26c-3161332c6aa7&segmentlength=10&protocolversion=3
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=240000,CODECS="mp4a.40.5,avc1.42c00d",RESOLUTION=400x224
http://api35-phx.unicornmedia.com/now/od/m3u8/guid-stuff/content.m3u8?visitguid=6c2aa0d0-0338-450f-b26c-3161332c6aa7&segmentlength=10&protocolversion=3

Less of issue more of question, sending headers with HLS requests

Amazon s3 allow secure links to files by setting auth header etc.. Is there an easy way to make HLS secure or where in the code would one do that. Is this feture already built in some where? Custom headers etc??

any help would be appreciated. We want to make sure only our website can access the HLS stream.

Unable to ((fast-) forward

Hi,
I'm using the example (https://github.com/videojs/videojs-contrib-hls/blob/master/example.html) to view my HLS stream.
It's working quite well, reading the m3u8 file:


#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-TARGETDURATION:50
#EXT-X-DISCONTINUITY
#EXTINF:40.533,
1-0.ts
#EXTINF:30.367,
1-1.ts
#EXTINF:49.991,
1-2.ts
#EXT-X-DISCONTINUITY
#EXTINF:0.116,
1-3.ts
#EXT-X-DISCONTINUITY
#EXTINF:31.900,
1-4.ts
#EXTINF:41.333,
1-5.ts
#EXTINF:39.867,
1-6.ts
#EXTINF:39.900,
1-7.ts
#EXTINF:39.833,
1-8.ts
#EXTINF:39.867,
1-9.ts
#EXTINF:39.900,
1-10.ts
#EXTINF:39.833,
1-11.ts
#EXTINF:7.633,
1-12.ts
#EXTINF:36.767,
1-13.ts

playback is working, but there's no timeline, so seeking impossible .... .

  • The stream starts at the beginning of the HLS stream, is there a way to tell video.js to start somewhere
    at live -5sec?

(Btw. Firefox (Ubuntu) played the stream quite well, now (reloading) the only thing i get is a black screen, saying 'LIVE';
Dolphin (Android) plays the stream, but there's no timeline either)

So, what do i have to change to get seeking support in here?

Thanks!

Cannot setup desired tech priority with the HLS tech

The HLS tech advertises support for HLS and all the formats the Flash tech can support. Unfortunately, this means that it's impossible to setup the tech as a polyfill for HLS support without involving Flash when it's not strictly required. If you have sources like this:

{ src: 'movie.mp4', type: 'video/mp4' },
{ src: 'movie.m3u8', type: 'application/x-mpegURL' }

and techOrder ['hls', 'html5'], despite the fact you may be on a browser that support mp4 natively, you will end up with the mp4 playing through the HLS tech.

cc @pcosta-bc

Measuring Good Behavior

We want to make it possible to answer the question, "Am I doing a good
job playing back video?" Contrary to intuition, that's not a simple
question. There are multiple axes on which we might wish to
optimize. For instance,

  • Continuity: how can I avoid stalls during playback?
  • Quality: how can I provide the highest fidelity video playback?
  • Speed: how can I begin playing back video as quickly as possible?
  • Economics: how can I minimize my costs to play back video?
  • Consistency: how can I minimize distracting quality changes during playback?

Reasonable people may disagree on the weighting each of those
questions have in the definition of "good." Our goal is to provide
statistics that allow video implementors to quantify how their player
is performing along the dimensions that are important to them.

Continuity

Continuous playback is a function of network conditions at the client
and the switching behavior of the player.

  • ratio of video played back to elapsed clock time
    (unit-less):

video-time / time

This quantity can be calculated by monitoring timeupdate events and
checking currentTime().

Quality

Though it's possible to produce high bitrate video that looks and
sounds terrible, it's generally safe to assume that more bits per
second mean better playback experiences.

  • ratio of bits of presented video to time played (b/s):

bits-presented / video-time

This metric would be derivable if the aggregate number of bits
presented to the viewer were available.

Speed

Initial playback time is dependent on the time to fetch stream
metadata and the download time of the first segment.

  • seconds from play request to first frame (s):

time(playing_i) - time(play_i)

This can be calculated from measuring the delay between the play and
playing events.

Economics

In most cases, the cost of delivering video is tied very closely to
the number of bits delivered.

  • ratio of bits of downloaded video to time played (b/s):

bits-downloaded / video-time

It would be possible to quantify this if the total number of video
bits downloaded were available.

Consistency

Consistency is almost an emergent property of other
behaviors. Choosing to be very responsive in the face of bandwidth
changes reduces consistency but decreases the probability that reduced
network conditions will result in a stall.

  • number of quality switches per second of playback (switches/s):

switch-count / video-time

It is possible to calculate this by periodically polling the active
playlist but would be more accessible if an event indicated a quality
switch or the total number of quality switches were exposed.

Background

What version of videojs to use

Poking around videojs trying to get a hls live stream to work. I noticed there is a hls branch in the videojs repo, as well as this separate repo. I was curious if a special build of videojs is required for this plugin. I cloned this repo and built it, but when I call .hls() on my player object it is undefined. Should I be using videojs built from a different branch?

Any guidance on how to make this work would be appreciated.

flv-tag.js, L81: Setting this.keyFrame always overrides prior initialization

In flv-tag.js, L81 I found this line:

this.keyFrame = extraData; // Defaults to false

which overrides prior initialization of keyFrame in L59, L67 and L71:

this.keyFrame = false; // :Boolean

  switch(type) {
  case hls.FlvTag.VIDEO_TAG:
    this.length = 16;
    break;
  case hls.FlvTag.AUDIO_TAG:
    this.length = 13;
    this.keyFrame = true;
    break;
  case hls.FlvTag.METADATA_TAG:
    this.length = 29;
    this.keyFrame = true;
    break;
  default:
    throw("Error Unknown TagType");
  }

I am confused as to what priority extraData should have. Is this perhaps the intended version?:

this.keyFrame = extraData; // Defaults to false

  switch(type) {
  case hls.FlvTag.VIDEO_TAG:
    this.length = 16;
    break;
  case hls.FlvTag.AUDIO_TAG:
    this.length = 13;
    this.keyFrame = true;
    break;
  case hls.FlvTag.METADATA_TAG:
    this.length = 29;
    this.keyFrame = true;
    break;
  default:
    throw("Error Unknown TagType");
  }

Now, if I use that version I'll get 6 errors in the unit tests. Is that because my version is incorrect? Or does this experiment point to other potential problems in the videojs-contrib-hls code base?

Please let me know if you need more information.

Bernd Paradies, Adobe Systems Inc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.