( session: CaptureSession, frameIndex: number, time: number, )
| 1768 | } |
| 1769 | |
| 1770 | export async function captureFrame( |
| 1771 | session: CaptureSession, |
| 1772 | frameIndex: number, |
| 1773 | time: number, |
| 1774 | ): Promise<CaptureResult> { |
| 1775 | const { options, outputDir } = session; |
| 1776 | const { buffer, quantizedTime, captureTimeMs } = await captureFrameCore( |
| 1777 | session, |
| 1778 | frameIndex, |
| 1779 | time, |
| 1780 | ); |
| 1781 | |
| 1782 | const ext = options.format === "png" ? "png" : "jpg"; |
| 1783 | const frameName = `frame_${String(frameIndex).padStart(6, "0")}.${ext}`; |
| 1784 | const framePath = join(outputDir, frameName); |
| 1785 | writeFileSync(framePath, buffer); |
| 1786 | |
| 1787 | return { frameIndex, time: quantizedTime, path: framePath, captureTimeMs }; |
| 1788 | } |
| 1789 | |
| 1790 | /** |
| 1791 | * Capture a frame and return the screenshot as a Buffer instead of writing to disk. |
no test coverage detected