Skip to content

Commit

Permalink
Merge pull request #1683 from StaZhu/gh-pages
Browse files Browse the repository at this point in the history
Add HEVC to MediaRecorder mimetypes list
  • Loading branch information
henbos authored Oct 18, 2024
2 parents b4d1578 + bc91085 commit 6a6b950
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 6a6b950

Please sign in to comment.