mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 02:43:48 +02:00
75 lines
2.2 KiB
HTML
75 lines
2.2 KiB
HTML
<button>Go</button>
|
|
|
|
<script src="../dist/bundles/mediabunny.cjs"></script>
|
|
<script src="../packages/mp3-encoder/dist/bundles/mediabunny-mp3-encoder.js"></script>
|
|
|
|
<script type="module">
|
|
function download(blob, filename) {
|
|
const url = URL.createObjectURL(blob);
|
|
const a = document.createElement('a');
|
|
a.href = url;
|
|
a.download = filename;
|
|
a.click();
|
|
URL.revokeObjectURL(url);
|
|
}
|
|
|
|
MediabunnyMp3Encoder.registerMp3Encoder();
|
|
|
|
const button = document.querySelector('button');
|
|
button.addEventListener('click', async () => {
|
|
const stream = await navigator.mediaDevices.getDisplayMedia({ video: true, audio: false });
|
|
const videoTrack = stream.getVideoTracks()[0];
|
|
const audioTrack = stream.getAudioTracks()[0];
|
|
|
|
const output = new Mediabunny.Output({
|
|
target: new Mediabunny.BufferTarget(),
|
|
format: new Mediabunny.Mp4OutputFormat(),
|
|
});
|
|
let videoSource = null;
|
|
let audioSource = null;
|
|
if (videoTrack) {
|
|
videoSource = new Mediabunny.MediaStreamVideoTrackSource(videoTrack, {
|
|
codec: 'vp9',
|
|
bitrate: Mediabunny.QUALITY_MEDIUM,
|
|
sizeChangeBehavior: 'passThrough',
|
|
});
|
|
|
|
videoSource.errorPromise.catch((d) => console.log("Hello?????", d));
|
|
|
|
output.addVideoTrack(videoSource);
|
|
}
|
|
if (audioTrack) {
|
|
audioSource = new Mediabunny.MediaStreamAudioTrackSource(audioTrack, {
|
|
codec: 'opus',
|
|
bitrate: Mediabunny.QUALITY_MEDIUM
|
|
});
|
|
|
|
audioSource.errorPromise.catch((d) => console.log("Hello!!???", d));
|
|
|
|
output.addAudioTrack(audioSource);
|
|
}
|
|
|
|
await output.start();
|
|
|
|
setTimeout(() => {
|
|
return;
|
|
videoSource?.pause();
|
|
audioSource?.pause();
|
|
|
|
setTimeout(() => {
|
|
videoSource?.resume();
|
|
audioSource?.resume();
|
|
}, 1000);
|
|
}, 1000);
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
|
|
await output.finalize();
|
|
|
|
console.log(output.target.buffer);
|
|
download(new Blob([output.target.buffer]), 'livetest' + output.format.fileExtension);
|
|
|
|
videoTrack?.stop();
|
|
audioTrack?.stop();
|
|
});
|
|
</script> |