Skip to content

Commit

Permalink
Merge pull request webrtc#1636 from fippo/muxer
Browse files Browse the repository at this point in the history
mediarecorder: improved support for MP4
  • Loading branch information
fippo authored Feb 29, 2024
2 parents 358eb24 + ec63947 commit b485ae6
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/content/getusermedia/record/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ playButton.addEventListener('click', () => {

const downloadButton = document.querySelector('button#download');
downloadButton.addEventListener('click', () => {
const blob = new Blob(recordedBlobs, {type: 'video/webm'});
const mimeType = codecPreferences.options[codecPreferences.selectedIndex].value.split(';', 1)[0];
const blob = new Blob(recordedBlobs, {type: mimeType});
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = 'test.webm';
a.download = mimeType === 'video/mp4' ? 'test.mp4' : 'test.webm';
document.body.appendChild(a);
a.click();
setTimeout(() => {
Expand Down Expand Up @@ -80,11 +81,21 @@ function getSupportedMimeTypes() {
});
}

function startRecording() {
async function startRecording() {
recordedBlobs = [];
const mimeType = codecPreferences.options[codecPreferences.selectedIndex].value;
const options = {mimeType};

if (mimeType.split(';', 1)[0] === 'video/mp4') {
// Adjust sampling rate to 48khz.
const track = window.stream.getAudioTracks()[0];
const {sampleRate} = track.getSettings();
if (sampleRate != 48000) {
track.stop();
window.stream.removeTrack(track);
const newStream = await navigator.mediaDevices.getUserMedia({audio: {sampleRate: 48000}});
window.stream.addTrack(newStream.getTracks()[0]);
}
}
try {
mediaRecorder = new MediaRecorder(window.stream, options);
} catch (e) {
Expand Down

0 comments on commit b485ae6

Please sign in to comment.