Skip to content

Commit

Permalink
Add HEVC to MediaRecorder mimetypes list
Browse files Browse the repository at this point in the history
HEVC MediaRecorder support will be available after:
https://chromium-review.googlesource.com/c/chromium/src/+/4707115

It will support `video/x-matroska` and `video/mp4` mimetypes.

Note that the latest Chromium also support VP9/AV1 `video/mp4`
encoding, so add them to the list as well.
  • Loading branch information
StaZhu committed Oct 17, 2024
1 parent b4d1578 commit bc91085
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/content/getusermedia/record/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ downloadButton.addEventListener('click', () => {
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = mimeType === 'video/mp4' ? 'test.mp4' : 'test.webm';
a.download = `test.${mimeTypeToFileExtension(mimeType)}`;
document.body.appendChild(a);
a.click();
setTimeout(() => {
Expand All @@ -61,6 +61,19 @@ downloadButton.addEventListener('click', () => {
}, 100);
});

function mimeTypeToFileExtension(mimeType) {
switch (mimeType) {
case 'video/mp4':
return 'mp4';
case 'video/webm':
return 'webm';
case 'video/x-matroska':
return 'mkv';
default:
throw new Error(`unsupported mimetype: ${mimeType}`);
}
}

function handleDataAvailable(event) {
console.log('handleDataAvailable', event);
if (event.data && event.data.size > 0) {
Expand All @@ -74,8 +87,12 @@ function getSupportedMimeTypes() {
'video/webm;codecs=vp8,opus',
'video/webm;codecs=h264,opus',
'video/webm;codecs=av01,opus',
'video/x-matroska;codecs=hvc1,opus',
'video/mp4;codecs=h264,aac',
'video/mp4;codecs=vp9,mp4a.40.2',
'video/mp4;codecs=avc1,mp4a.40.2',
'video/mp4;codecs=hvc1,mp4a.40.2',
'video/mp4;codecs=av01,mp4a.40.2',
'video/mp4',
];
return possibleTypes.filter(mimeType => {
Expand Down

0 comments on commit bc91085

Please sign in to comment.