Recording cross-platform (H.264?) videos using Web

2019-06-16 06:56发布

问题:

I have the following specified with my MediaRecorder implementation:

const getMediaRecorderOptions = function () {
    var options = { mimeType: "video/webm;codecs=vp8" }; // 9 was lagggy, cpu-intensive

    if (!MediaRecorder.isTypeSupported(options.mimeType)) {
        logger.recorderLog(options.mimeType + " is not Supported");
        options = { mimeType: "video/webm;codecs=vp8" };

        if (!MediaRecorder.isTypeSupported(options.mimeType)) {
            logger.recorderLog(options.mimeType + " is not Supported");
            options = { mimeType: "video/webm" };

            if (!MediaRecorder.isTypeSupported(options.mimeType)) {
                logger.recorderLog(options.mimeType + " is not Supported");
                options = { mimeType: "" };
            }
        }
    }
    return options;
}

Obviously, this is just for webm which isn't supported on iOS Safari or MacOS. I'm trying to avoid doubling our storage and introducing encoding complexity. Is there any way MediaRecorder on Chrome can record directly to a cross-platform container format, from any platform?

回答1:

You should be able to record to webm/h.264

var options = {mimeType: 'video/webm;codecs=h264'};

media_recorder = new MediaRecorder(stream, options);

So you have the right cross platform video format (H.264) in a WebM container.

Now you could try ffmpeg.js and just change the container from WebM to mp4 - coping the H.264 stream - no transcoding (-vcodec copy).

I recorded to webm/h.264 in Chrome but I didn't try re-wrapping it with ffmpeg.js.