MCPcopy Index your code
hub / github.com/EmulatorJS/EmulatorJS / screenRecord

Method screenRecord

data/src/emulator.js:6073–6156  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6071 }
6072
6073 screenRecord() {
6074 const captureFps = this.getSettingValue("screenRecordingFPS") || this.capture.video.fps;
6075 const captureFormat = this.getSettingValue("screenRecordFormat") || this.capture.video.format;
6076 const captureUpscale = this.getSettingValue("screenRecordUpscale") || this.capture.video.upscale;
6077 const captureVideoBitrate = this.getSettingValue("screenRecordVideoBitrate") || this.capture.video.videoBitrate;
6078 const captureAudioBitrate = this.getSettingValue("screenRecordAudioBitrate") || this.capture.video.audioBitrate;
6079 const aspectRatio = this.gameManager.getVideoDimensions("aspect") || 1.333333;
6080 const videoRotation = parseInt(this.getSettingValue("videoRotation") || 0);
6081 const videoTurned = (videoRotation === 1 || videoRotation === 3);
6082 let width = 800;
6083 let height = 600;
6084 let frameAspect = this.canvas.width / this.canvas.height;
6085 let canvasAspect = width / height;
6086 let offsetX = 0;
6087 let offsetY = 0;
6088
6089 const captureCanvas = document.createElement("canvas");
6090 const captureCtx = captureCanvas.getContext("2d", { alpha: false });
6091 captureCtx.fillStyle = "#000";
6092 captureCtx.imageSmoothingEnabled = false;
6093 const updateSize = () => {
6094 width = this.canvas.width;
6095 height = this.canvas.height;
6096 frameAspect = width / height
6097 if (width >= height && !videoTurned) {
6098 width = height * aspectRatio;
6099 } else if (width < height && !videoTurned) {
6100 height = width / aspectRatio;
6101 } else if (width >= height && videoTurned) {
6102 width = height * (1/aspectRatio);
6103 } else if (width < height && videoTurned) {
6104 width = height / (1/aspectRatio);
6105 }
6106 canvasAspect = width / height;
6107 captureCanvas.width = width * captureUpscale;
6108 captureCanvas.height = height * captureUpscale;
6109 captureCtx.scale(captureUpscale, captureUpscale);
6110 if (frameAspect > canvasAspect) {
6111 offsetX = (this.canvas.width - width) / -2;
6112 } else if (frameAspect < canvasAspect) {
6113 offsetY = (this.canvas.height - height) / -2;
6114 }
6115 }
6116 updateSize();
6117 this.addEventListener(this.canvas, "resize", () => {
6118 updateSize();
6119 });
6120
6121 let animation = true;
6122
6123 const drawNextFrame = () => {
6124 captureCtx.drawImage(this.canvas, offsetX, offsetY, this.canvas.width, this.canvas.height);
6125 if (animation) {
6126 requestAnimationFrame(drawNextFrame);
6127 }
6128 };
6129 requestAnimationFrame(drawNextFrame);
6130

Callers 1

createContextMenuMethod · 0.95

Calls 7

getSettingValueMethod · 0.95
addEventListenerMethod · 0.95
getBaseFileNameMethod · 0.95
getVideoDimensionsMethod · 0.80
createElementMethod · 0.80
removeMethod · 0.45

Tested by

no test coverage detected