Created
April 6, 2022 09:19
-
-
Save mkopa/5f93ac125cd7f925dcde9aae72dee50d to your computer and use it in GitHub Desktop.
Get all supported MimeType types (copy and paste the code into your web browser console)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getSupportedMimeTypes(media, types, codecs) { | |
| const isSupported = MediaRecorder.isTypeSupported; | |
| const supported = []; | |
| types.forEach((type) => { | |
| const mimeType = `${media}/${type}`; | |
| codecs.forEach((codec) => [ | |
| `${mimeType};codecs=${codec}`, | |
| `${mimeType};codecs:${codec}`, | |
| `${mimeType};codecs=${codec.toUpperCase()}`, | |
| `${mimeType};codecs:${codec.toUpperCase()}` | |
| ].forEach(variation => { | |
| if(isSupported(variation)) | |
| supported.push(variation); | |
| })); | |
| if (isSupported(mimeType)) | |
| supported.push(mimeType); | |
| }); | |
| return supported; | |
| }; | |
| // Usage ------------------ | |
| const videoTypes = ["webm", "ogg", "mp4", "x-matroska"]; | |
| const audioTypes = ["webm", "ogg", "mp3", "x-matroska"]; | |
| const codecs = ["vp9", "vp9.0", "vp8", "vp8.0", "avc1", "av1", "h265", "h.265", "h264", "h.264", "opus", "pcm", "aac", "mpeg", "mp4a"]; | |
| const supportedVideos = getSupportedMimeTypes("video", videoTypes, codecs); | |
| const supportedAudios = getSupportedMimeTypes("audio", audioTypes, codecs); | |
| console.log('-- Top supported Video : ', supportedVideos[0]) | |
| console.log('-- Top supported Audio : ', supportedAudios[0]) | |
| console.log('-- All supported Videos : ', supportedVideos) | |
| console.log('-- All supported Audios : ', supportedAudios) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment