MCPcopy
hub / github.com/KilledByAPixel/LittleJS / debugVideoCaptureStart

Function debugVideoCaptureStart

src/engineDebug.js:593–665  ·  view source on GitHub ↗

Start capturing video * @memberof Debug

()

Source from the content-addressed store, hash-verified

591/** Start capturing video
592 * @memberof Debug */
593function debugVideoCaptureStart()
594{
595 ASSERT(!debugVideoCaptureIsActive(), 'Already capturing video!');
596
597 if (!debugVideoCaptureIcon)
598 {
599 // create recording icon to show it is capturing video
600 debugVideoCaptureIcon = document.createElement('div');
601 debugVideoCaptureIcon.style.position = 'absolute';
602 debugVideoCaptureIcon.style.padding = '9px';
603 debugVideoCaptureIcon.style.color = '#f00';
604 debugVideoCaptureIcon.style.font = '50px monospace';
605 document.body.appendChild(debugVideoCaptureIcon);
606 }
607 // show recording icon
608 debugVideoCaptureIcon.textContent = '';
609 debugVideoCaptureIcon.style.display = '';
610
611 // setup captureStream to capture manually by passing 0
612 const stream = mainCanvas.captureStream(0);
613 const videoTrack = stream.getVideoTracks()[0];
614 const captureTimer = new Timer(0, true);
615 const chunks = [];
616 videoTrack.applyConstraints({frameRate:frameRate});
617
618 // set up the media recorder
619 const mediaRecorder = new MediaRecorder(stream,
620 {mimeType:'video/webm;codecs=vp8'});
621 mediaRecorder.ondataavailable = (e)=> chunks.push(e.data);
622 mediaRecorder.onstop = ()=>
623 {
624 const blob = new Blob(chunks, {type: 'video/webm'});
625 const url = URL.createObjectURL(blob);
626 saveDataURL(url, 'capture.webm', 1e3);
627 };
628
629 let audioStreamDestination, silentAudioSource;
630 if (soundEnable)
631 {
632 // create silent audio source
633 // fixes issue where video can not start recording without audio
634 silentAudioSource = new ConstantSourceNode(audioContext, { offset: 0 });
635 silentAudioSource.connect(audioMasterGain);
636 silentAudioSource.start();
637
638 // connect to audio master gain node
639 audioStreamDestination = audioContext.createMediaStreamDestination();
640 audioMasterGain.connect(audioStreamDestination);
641 for (const track of audioStreamDestination.stream.getAudioTracks())
642 stream.addTrack(track); // add audio tracks to capture stream
643 }
644
645 // start recording
646 try { mediaRecorder.start(); }
647 catch(e)
648 {
649 LOG('Video capture not supported in this browser!');
650 silentAudioSource?.stop();

Callers 1

debugUpdateFunction · 0.70

Calls 7

saveDataURLFunction · 0.85
connectMethod · 0.80
ASSERTFunction · 0.70
LOGFunction · 0.70
startMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected