simularium / simularium-viewer

NPM package to view Simularium trajectories in 3D
Apache License 2.0
2 stars 0 forks source link

Feature/mp4 download #344

Closed interim17 closed 7 months ago

interim17 commented 10 months ago

Problem

Users of Simularium want to download mp4 video. It's already marked closed, but this addresses #240

Approach

FrameRecorder class handles the frame by frame recording of the canvas. Aimed for a good separation of concerns: using recorder to just record; front end handles downloading, etc.

Viewport.tsx makes an instance of FrameRecorder and watches for a boolean flag, recording. recorder.onFrame() is called in the animate() loop to keep frame capture tightly coupled to scene updates.

Viewer.tsx stores recording in state, and defines onRecordedMovie for handling recorded the output.

RecordMovieComponent buttons and a print of recording duration, this can get fleshed out more if desired?

onCompletedRecording could also send other data if wanted, number of frames, total duration of frames, etc.

There was a bug that I discussed with @toloudis that I still don't fully understand, where the canvas reference would go stale and return blank frames after changing Simularium files. Instantiating a new VideoEncoder on each call of setup() fixed the problem, but I'm still curious why the old encoder went stale, as it doesn't receive a canvas reference at all...

To confirm:

github-actions[bot] commented 10 months ago

jest coverage report πŸ§ͺ

Total coverage

Status Category Percentage Covered / Total
πŸ”΄ Statements 40.51% 2044/5045
πŸ”΄ Branches 43.53% 845/1941
πŸ”΄ Functions 36.9% 417/1130
πŸ”΄ Lines 40.72% 1957/4805

Status of coverage: 🟒 - ok, 🟑 - slightly more than threshold, πŸ”΄ - under the threshold

Show new covered files πŸŒ‘ ### Coverage of new files | Status | Filename | Statements | Branches | Functions | Lines | | :----: | :--------------- | :--------- | :------- | :-------- | :------ | | πŸ”΄ | FrameRecorder.ts | 29.62% | 33.33% | 25% | 29.48% | > Status of coverage: 🟒 - ok, 🟑 - slightly more than threshold, πŸ”΄ - under the threshold
Show files with reduced coverage πŸ”» ### Reduced coverage | Status | Filename | Statements | Branches | Functions | Lines | | :----: | :------------- | :----------------- | :----------------- | :----------------- | :----------------- | | 🟑 | src | 75.21% | 69.09% | 44.18% (-1.05% πŸ”») | 75.45% | | 🟑 | constants.ts | 78.94% (-3.41% πŸ”») | 100% | 50% (-7.14% πŸ”») | 77.77% (-3.48% πŸ”») | | 🟑 | src/simularium | 60.51% (-1.77% πŸ”») | 58.45% (-1.86% πŸ”») | 49.01% | 61.39% (-1.86% πŸ”») | | πŸ”΄ | src/viewport | 15.38% | 11.26% | 15.78% | 14.92% | | πŸ”΄ | index.tsx | 15.38% | 11.26% | 15.78% | 14.92% | > Status of coverage: 🟒 - ok, 🟑 - slightly more than threshold, πŸ”΄ - under the threshold
interim17 commented 7 months ago

Haven't tested locally but the code changes look good. Thank you for making edits!

Thanks for review! I do want to clean up the test-bed viewer a bit so I appreciate the push to do that right.