Hls.js: drawCanvas screenshot blank in Safari

Created on 26 Jun 2018  路  7Comments  路  Source: video-dev/hls.js

Environment
Steps to reproduce
  1. Embed your getting started code onto a page
  2. Add a button with the code to draw the video to canvas:

<button id="capture" class="button">Capture</button>

var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var capture = document.getElementById('capture');
capture.addEventListener('click', function(e) {
  ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
});
  1. Notice how the canvas is empty on Safari browsers only http://jsfiddle.net/kmturley/pch4dew5/13/
  2. Now comment out your feature detection and see it work in Safari: http://jsfiddle.net/pch4dew5/4/
Expected behavior

I expect to be able to draw the video frame to canvas, whether it's the native video player, or hls.js taking over

Actual behavior

Canvas is empty. I believe Safari supports HLS, so is inserting the js player, but that is somehow preventing drawImage. I don't think it's CORS, because the same code/video works without HLS.js loading the source

If I flip the if statements it works because it uses mpegurl for safari:

if (el.canPlayType('application/vnd.apple.mpegurl')) {
  // do something
} else if (Hls.isSupported()) {
  // do something else
}

http://jsfiddle.net/kmturley/pch4dew5/11/

Browser issue

Most helpful comment

I came upon this thread while researching a similar problem.

Here is what my extensive testing has told me so far:

  • iOS Safari does not allow context.drawImage() to work on HLS video streams for some reason. However, it works fine on MP4.

  • IE11 does not support MediaSource which is what HLS.js uses IF you are on Windows 7. However, MediaSource is supported on Windows 8.1+ so HLS.js works on those.

  • IE11 does not support HLS natively.

Good luck!

All 7 comments

IE11 is also having issues with drawImage. The image displays but is squashed, even though the dimensions are reported correctly:
http://jsfiddle.net/kmturley/q8fqLdaj/47/

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Any resolution?

I came upon this thread while researching a similar problem.

Here is what my extensive testing has told me so far:

  • iOS Safari does not allow context.drawImage() to work on HLS video streams for some reason. However, it works fine on MP4.

  • IE11 does not support MediaSource which is what HLS.js uses IF you are on Windows 7. However, MediaSource is supported on Windows 8.1+ so HLS.js works on those.

  • IE11 does not support HLS natively.

Good luck!

This issue is not hls.js related but solely to browser impl of HTMLMediaElement and respective canvas image copy.

if (el.canPlayType('application/vnd.apple.mpegurl')) { // do something } else if (Hls.isSupported()) { // do something else }

this can really work!!

if (el.canPlayType('application/vnd.apple.mpegurl')) { // do something } else if (Hls.isSupported()) { // do something else }

this can really work!!

It works fine on all desktop browsers I tested but I find the canPlayType("mimeType") is really 50/50 depending on the mobile device you're using.

Many mobile devices erroneously report "maybe" as a response which means it's unsure until you physically try to play it back. I've seen that sometimes, "maybe" does mean it can play while other times, it fails.

The response "maybe" is basically useless since it's not a deterministic answer.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jlacivita picture jlacivita  路  3Comments

bharathsn0812 picture bharathsn0812  路  4Comments

osamay picture osamay  路  4Comments

NicholasAsimov picture NicholasAsimov  路  3Comments

neuman picture neuman  路  4Comments