From bdd90582f57a384a1f84f663d850b0c2e388b071 Mon Sep 17 00:00:00 2001 From: Joe Heffernan Date: Thu, 16 Nov 2023 10:47:34 -0800 Subject: [PATCH] reorganize some lines and comments --- examples/RecordMovieComponent.tsx | 7 +++---- src/simularium/StreamRecorder.tsx | 14 +++++--------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/examples/RecordMovieComponent.tsx b/examples/RecordMovieComponent.tsx index 56064d14..6f92e108 100644 --- a/examples/RecordMovieComponent.tsx +++ b/examples/RecordMovieComponent.tsx @@ -1,5 +1,5 @@ import React, { useState, useEffect, useRef } from "react"; -import Recorder from "../src/simularium/StreamRecorder"; +import StreamRecorder from "../src/simularium/StreamRecorder"; interface RecordMovieComponentProps { trajectoryTitle: string; @@ -8,18 +8,18 @@ interface RecordMovieComponentProps { const RecordMovieComponent = ({ trajectoryTitle, }: RecordMovieComponentProps) => { + const recorderRef = useRef(null); const [isRecording, setIsRecording] = useState(false); let [recordingDuration, setRecordingDuration] = useState(0); let [recordingStatus, setRecordingStatus] = useState("Not recording"); let [outputStatus, setOutputStatus] = useState(""); - const recorderRef = useRef(null); useEffect(() => { // Access the existing canvas element const canvasEl = document.querySelector("canvas"); if (canvasEl) { - recorderRef.current = new Recorder(canvasEl, trajectoryTitle); + recorderRef.current = new StreamRecorder(canvasEl, trajectoryTitle); } }, [trajectoryTitle]); @@ -49,7 +49,6 @@ const RecordMovieComponent = ({ }; const stopRecording = async () => { - // when we start recording again, reset ouput status to recording in progress if (recorderRef.current) { setIsRecording(false); setRecordingStatus("Not recording"); diff --git a/src/simularium/StreamRecorder.tsx b/src/simularium/StreamRecorder.tsx index bc58461d..0d8a40e1 100644 --- a/src/simularium/StreamRecorder.tsx +++ b/src/simularium/StreamRecorder.tsx @@ -1,11 +1,11 @@ import { ArrayBufferTarget, Muxer } from "mp4-muxer"; -// TODO: this is working but the type is throwing an error, what is best practice here? -class Recorder { +class StreamRecorder { private canvasEl: HTMLCanvasElement; private encoder: VideoEncoder; private frameCounter: number; + // TODO: this is working but the linter is throwing a type error, what is best practice here? private trackProcessor: MediaStreamTrackProcessor; private reader: ReadableStreamDefaultReader; private muxer?: Muxer; @@ -13,8 +13,6 @@ class Recorder { private trajectoryTitle: string; constructor(canvasEl: HTMLCanvasElement, trajectoryTitle: string) { - // this is defined in the Viewer component - // TODO should this be handled differently to make it more flexible when embedding in other applications this.canvasEl = canvasEl; this.trajectoryTitle = trajectoryTitle; // VideoEncoder sends chunks of frame data to the muxer @@ -84,10 +82,9 @@ class Recorder { if (this.encoder.encodeQueueSize > 2) { frame.close(); // Drop the frame if encoder is overwhelmed } else { - // if recording and the queue is not full, encode the frame and then close it - // encoder is passing chunks to muxer + // if recording and the queue is healthy, encode the frame and then close it // don't entirely understand the use of keyFrames - // this is from the docs and will make the resulting video larger but also scrubbable + // this application is straight from the docs and will make the resulting file larger but also scrubbable // can optimize/alter these parameters? this.frameCounter++; const keyFrame = this.frameCounter % 150 === 0; @@ -114,7 +111,6 @@ class Recorder { const videoBlob = new Blob([buffer], { type: "video/mp4" }); const url = URL.createObjectURL(videoBlob); this.download(this.trajectoryTitle + ".mp4", url); - URL.revokeObjectURL(url); } @@ -128,4 +124,4 @@ class Recorder { } } -export default Recorder; +export default StreamRecorder;