From d281939a47bccfd03bc3a45f38a73bb2b4ff7e5f Mon Sep 17 00:00:00 2001 From: clover caruso Date: Fri, 8 May 2026 20:58:01 -0700 Subject: [PATCH] fix: ffmpeg progress tracker didn't consider fractional framerates honestly such a stupid thing like yeah i want to have 29.97 fps like no go be a normal human being. fixes #35 --- lib/subprocess/ffmpeg.test.ts | 20 ++++++++++++++++++++ lib/subprocess/ffmpeg.ts | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 lib/subprocess/ffmpeg.test.ts diff --git a/lib/subprocess/ffmpeg.test.ts b/lib/subprocess/ffmpeg.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..9e58ac2263ca4631ca88585789e3f330ea54f83d --- /dev/null +++ b/lib/subprocess/ffmpeg.test.ts @@ -0,0 +1,20 @@ +test("Parse uses fractional input fps for total frame estimates", () => { + const parser = new Parse(); + + parser.onLine("Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':"); + parser.onLine(" Duration: 00:01:08.10, start: 0.000000, bitrate: 352 kb/s"); + parser.onLine( + " Stream #0:0[0x1](und): Video: h264, yuv420p(progressive), 160x90, 351 kb/s, 29.97 fps, 29.97 tbr, 30k tbn (default)", + ); + + const result = parser.onLine( + "frame= 2041 fps=0.0 q=-1.0 Lsize=N/A time=00:01:08.10 bitrate=N/A speed= 900x", + ); + + assert.equal(result.kind, "progress"); + assert.equal(result.totalFrames, 2041); +}); + +import assert from "node:assert"; +import { test } from "vitest"; +import { Parse } from "./ffmpeg.ts"; diff --git a/lib/subprocess/ffmpeg.ts b/lib/subprocess/ffmpeg.ts index d9e526ad1e5ba3ff63aa31cbde1a09fd7077a479..2b29e1f12a2f39e1ff65443b71d2cedc451463c5 100644 --- a/lib/subprocess/ffmpeg.ts +++ b/lib/subprocess/ffmpeg.ts @@ -161,7 +161,7 @@ export class Parse { ); } if (!this.targetFps) { - const match = line.match(/^Stream.*, (\d+) fps/); + const match = line.match(/^Stream.*, (\d+(?:\.\d+)?) fps/); if (match) this.targetFps = Number(match[1]); } } -- 2.54.0