5

MediaRecorder.isTypeSupported('video/mp4') is false in Chrome. So I found MediaStreamRecorder https://github.com/streamproc/MediaStreamRecorder then I did

var recorder = new MediaStreamRecorder(stream, {
  mimeType: 'video/mp4',
});
// also
recorder.mimeType = 'video/mp4';

But the output is webm as I checked with ffmpeg -i

Input #0, matroska,webm, from '/Users/otiai10/Downloads/example.mp4':
  Metadata:
    encoder         : Chrome
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0(eng): Video: vp8, yuv420p, 640x480, SAR 1:1 DAR 4:3, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)

The video is playable in Chrome but NOT on QuickTime Player, in evidence.

Here are more details and (not!) working example of this problem.

It was said muaz-khan/Ffmpeg.js can convert webm to mp4, but the file size matters.

Is there any workaround to record and save as mp4?

otiai10
  • 4,289
  • 5
  • 38
  • 50

3 Answers3

9

OK, that was my misunderstanding.

See https://github.com/streamproc/MediaStreamRecorder/issues/117 for more details.

MediaStreamRecorder can record audio as WAV and video as either WebM or animated gif on Chrome

no mp4 possible.

otiai10
  • 4,289
  • 5
  • 38
  • 50
2

Checkout ffmpeg.wasm

You can install it via:

# Use npm
$ npm install @ffmpeg/ffmpeg @ffmpeg/core
# Use yarn
$ yarn add @ffmpeg/ffmpeg @ffmpeg/core

And then, you can convert your blobs into an mp4 file. Checkout the example that they provided in the link I shared.

ilpianoforte
  • 1,180
  • 1
  • 10
  • 28
0

Whilst it isn't possible to directly record in mp4, you can pass the resulting webm file to webm-to-mp4 to have it converted:

const webmToMp4 = require("webm-to-mp4")
 
const mp4 = webmToMp4(webm)

The module can be compiled to work in the browser since it uses ffmpeg.js under the hood.

Richie Bendall
  • 7,738
  • 4
  • 38
  • 58
  • This is an interesting concept. Do you know of any implementations of this? (encoding mp4 direct on the client side browser)? – Phil Sep 09 '21 at 14:15
  • 1
    This implements a browser-friendly build of ffmpeg so that it will work in the browser. – Richie Bendall Sep 11 '21 at 04:05