| 426 | } |
| 427 | |
| 428 | async function renderCanvasToVideoFrameAndEncode({ |
| 429 | canvas, |
| 430 | videoEncoder, |
| 431 | frameNumber, |
| 432 | fps, |
| 433 | }) { |
| 434 | let frame = new VideoFrame(animation, { |
| 435 | // Equally spaces frames out depending on frames per second |
| 436 | timestamp: (frameNumber * 1e6) / fps, |
| 437 | }); |
| 438 | |
| 439 | // The encode() method of the VideoEncoder interface asynchronously encodes a VideoFrame |
| 440 | videoEncoder.encode(frame); |
| 441 | |
| 442 | // The close() method of the VideoFrame interface clears all states and releases the reference to the media resource. |
| 443 | frame.close(); |
| 444 | } |
| 445 | |
| 446 | function downloadBlob() { |
| 447 | console.log("download video"); |