All MIME types supported by MediaRecorder in Firefox and Chrome?

前端 未结 6 613
广开言路
广开言路 2020-12-05 04:50

Where can I find a list of all MIME types that are supported by Firefox or Chrome? All examples I\'ve seen so far using video/webm onl

6条回答
  •  没有蜡笔的小新
    2020-12-05 05:16

    I made this small function in my utils.js to get the best supported codec, with support for multiple possible naming variations (example : firefox support video/webm;codecs:vp9 but not video/webm;codecs=vp9

    You can reorder the VIDEO_CODECS array by priority, so you can always fall to next best supported codec.

    function getSupportedMimeTypes() {
      const VIDEO_TYPES = [
        "webm", 
        "ogg",
        "mp4",
        "x-matroska"
      ];
      const VIDEO_CODECS = [
        "vp9",
        "vp9.0",
        "vp8",
        "vp8.0",
        "avc1",
        "av1",
        "h265",
        "h.265",
        "h264",
        "h.264",
        "opus",
      ];
    
      const supportedTypes = [];
      VIDEO_TYPES.forEach((videoType) => {
        const type = `video/${videoType}`;
        VIDEO_CODECS.forEach((codec) => {
            const variations = [
            `${type};codecs=${codec}`,
            `${type};codecs:${codec}`,
            `${type};codecs=${codec.toUpperCase()}`,
            `${type};codecs:${codec.toUpperCase()}`
          ]
          variations.forEach(variation => {
            if(MediaRecorder.isTypeSupported(variation)) 
                supportedTypes.push(variation);
          })
        });
        if (MediaRecorder.isTypeSupported(type)) supportedTypes.push(type);
      });
      return supportedTypes;
    }
    
    const supportedMimeTypes = getSupportedMimeTypes();
    console.log('Best supported mime types by priority : ', supportedMimeTypes[0])
    console.log('All supported mime types ordered by priority : ', supportedMimeTypes)

提交回复
热议问题