| 477 | } |
| 478 | |
| 479 | async function decodeGray(filePath) { |
| 480 | const args = [ |
| 481 | "-v", "error", |
| 482 | "-i", filePath, |
| 483 | "-vf", `scale=${ANALYSIS_WIDTH}:${ANALYSIS_HEIGHT}:flags=fast_bilinear,format=gray`, |
| 484 | "-f", "rawvideo", |
| 485 | "-" |
| 486 | ]; |
| 487 | const { stdout } = await run(FFMPEG, args, { encoding: "buffer" }); |
| 488 | const frameSize = ANALYSIS_WIDTH * ANALYSIS_HEIGHT; |
| 489 | const frameCount = Math.floor(stdout.length / frameSize); |
| 490 | const frames = new Array(frameCount); |
| 491 | for (let i = 0; i < frameCount; i += 1) { |
| 492 | frames[i] = stdout.subarray(i * frameSize, (i + 1) * frameSize); |
| 493 | } |
| 494 | return frames; |
| 495 | } |
| 496 | |
| 497 | function stats(frame) { |
| 498 | let sum = 0; |