Recording Video HTML5 not working in Safari and iOS mobile app

Viewed 708

I am trying to use the HTML5 video - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video to access camera on the device.

I am following this example - https://developer.mozilla.org/en-US/docs/Web/API/MediaStream_Recording_API/Recording_a_media_element to record the video.

It works perfectly in Chrome browser but does not seem to be working on Safari and iOS mobile app. On debugging both captureStream() and mozCaptureStream() functions are undefined.

Any suggestions on how to fix this?

PS: Is this a known issue - https://bugs.webkit.org/show_bug.cgi?id=181663. Are there any workarounds? Thanks!

2 Answers

I don't think recording webcam as video is an available option on Apple devices.
It might be a licensing issue rather than a technical limitation.

It works perfectly in Chrome browser but does not seem to be working on Safari and iOS mobile app. On debugging both captureStream() and mozCaptureStream() functions are undefined.

  1. Your link is recording into Google's own webM video which is a format not supported by Apple. The Safari browser cannot encode pixels as VP8 or VP9 to use inside webM container. Apple has an MPEG video license so for Safari, I expect MP4 to be their expected output (but is there a free H264 encoder inside Safari? Nope).

  2. mozCaptureStream() is specific to Mozilla Firefox. Safari won't know/accept it.

  3. captureStream() is not fully suppported on Safari. The missing part is the recording part.

Possible workarounds:

I've been banging my head on getting captureStream to work on iOS (Safari and Chrome, same results) to no avail. This reply by @VC.One helped me stop trying to use webM format, which was used by the sample code I was following from mdn which is here... https://developer.mozilla.org/en-US/docs/Web/API/MediaStream_Recording_API/Recording_a_media_element

So I simply switched to mp4 instead of webm, using .srcObject instead of .captureStream, and now I have things working on iOS. I still have a lot of clean-up to do, but when my solution is finished I will make a nice write-up and post back.

Also, someone pointed out that I needed to use the onloadedmetadata with the play method, in order to get a video element to show a real-time feed of bytes from getUserMedia, and that worked. Then I just needed to store the bytes somewhere that iOS will not freak out about (it does not support captureStream) and then it all came together. It definitely seems to be a licensing issue at the heart of it all, which is why this works using mp4 instead of webm.

Related