Skip to content

Commit

Permalink
Don't ajust audio track if there is no audio track (#1691)
Browse files Browse the repository at this point in the history
On a M4 Mac Mini, there is no built-in microphone or
camera, so `getAudioTracks()` will always return an
empty array. In this case, we don't need to ajust
sampling rate to 48khz...

Also change av1 codecs string from `av01.1.x.y` to
`av01.0.x.y` since MediaRecorder only support av1
main profile instead of high profile.

Co-authored-by: Harald Alvestrand <[email protected]>
  • Loading branch information
StaZhu and alvestrand authored Jan 4, 2025
1 parent 161f6e7 commit 65f8969
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/content/getusermedia/record/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function getSupportedMimeTypes() {
'video/mp4;codecs=avc3.64003E,mp4a.40.2',
'video/mp4;codecs=hvc1.1.6.L186.B0,mp4a.40.2',
'video/mp4;codecs=hev1.1.6.L186.B0,mp4a.40.2',
'video/mp4;codecs=av01.1.19M.08,mp4a.40.2',
'video/mp4;codecs=av01.0.19M.08,mp4a.40.2',
'video/mp4',
];
return possibleTypes.filter(mimeType => {
Expand All @@ -108,12 +108,14 @@ async function startRecording() {
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]);
if (track) {
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 {
Expand Down

0 comments on commit 65f8969

Please sign in to comment.