Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
[issue-11638] Fix FFmpeg frame extraction output sync (#11640)
[._.]/a8f5d42773c7
diff --git a/server/lib/README.md b/server/lib/README.mdindex 5f7f843757..5cb025a148 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -439,7 +439,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| `httpDrain.js` | `createHttpDrain(servers)` tracks every ordinary request the HTTP listeners accept; `begin(windowMs)` is the synchronous shutdown step that stops intake on all of them (`server.close()` plus a 503 `Connection: close` gate for requests arriving on still-open keep-alive sockets), turns off keep-alive on in-flight responses, drops open SSE streams, and resolves `{ remaining }` once accepted requests finish or the window ends (#8323). || `httpCompression.js` | `httpCompression` negotiates Brotli/gzip for API and static responses while preserving streaming, ranges, existing encodings, and `no-transform`. || `execGit.js` | `execGit(args, cwd, options)` and `execGitSafe(args, cwd, options)` shared process boundary for Git operations, worktrees, and `services/forgeAuth.js` credential resolution. The safe variant converts rejections into `{ exitCode: 1, stdout: '', stderr }`; `services/git.js` re-exports both for compatibility. `cwd` is REQUIRED — it rejects on a missing/blank one rather than letting `spawn` fall back to `process.cwd()` and run git against PortOS's own checkout (#4554). |-| `ffmpeg.js` | Shared ffmpeg helpers (videoGen + videoTimeline). `probeVideoGeometry(videoPath)` measures a finished clip's `{ width, height, fps, numFrames, durationSec }` (null when any axis is unreadable) for hosted renders that record no frame count. `generateThumbnail(videoPath, jobId, { atSec } = {})` accepts a clamped poster seek while preserving the single-clip default. Includes `probeFrameCount(videoPath)` (metadata `nb_frames`, falling back to a real `-count_frames` pass — expensive, so call it once per file) and `trimVideoFromFrame(videoPath, outPath, {startFrame, fps})` — a frame-EXACT head cut via the `trim` filter (an `-ss` seek can drift a frame, which reads as a stutter at a stitch seam), keeping audio in sync with `atrim` when the clip has a soundtrack and taking `-an` when it doesn't. Re-encodes by necessity, so a later concat must re-encode too; `outPath` may equal the input (temp-file + rename install). Used by the chained-render context window — see `videoContinuity.js`. `buildTrimConcatArgs({inputs, outPath, width, height, fps, withAudio})` builds the argv for the other half of that job: a concat that drops leading frames from some of its inputs inside a `filter_complex` graph, so the cuts ride along with the timeline encode instead of costing one pre-encode per clip (pass `withAudio` only when EVERY input has an audio stream — check with `hasAudioStream`). `buildExtendSpliceArgs({sourcePath, generatedPath, outPath, keepFrames, newStartFrame, width, height, fps, audio, sourceAudioPath, masterOutPath})` is the plain-Extend counterpart: source frames `[0, keep)` + render frames from `newStartFrame`, one encode, audio crossfaded (~40 ms linear) at the seam; `sourceAudioPath` swaps the source span's audio for a lossless master and `masterOutPath` also writes the mix as a 24-bit FLAC master, so the delivered AAC is encoded once from PCM. Its stream-copy sibling is `buildExtendNewSpanArgs` (encode only the render's new span) + `buildExtendConcatList` + `buildExtendCopyArgs` (join it to the untouched source with `-c:v copy`); `probeVideoCodecSignature` gates it and `videoFrameHashes` (per-frame MD5) proves the join before anything is replaced; `audioFingerprint` / `sealAudioMaster` / `readAudioMasterFingerprint` bind a master to the exact decoded soundtrack it was mixed for so a replaced soundtrack invalidates it — driven by `services/videoGen/extendSplice.js`. `H264_ENCODE_ARGS` / `AAC_ENCODE_ARGS` are the shared encode profile: clips produced by different paths here get concatenated together, so a mismatch shows up as one segment graded differently from its neighbours — spread these rather than re-typing the flags. Every re-encode here also pins BT.709: `BT709_CONTAINER_ARGS` (the `colr` atom, always emitted) plus `bt709TagFilter()` → the `BT709_TAG_FILTER` `setparams=…` string, or `null` on an ffmpeg without that filter (`supportsSetparamsFilter()` probes `-filters` once per process; `null` = not probed, and a probe that couldn't run stays uncached). Both halves are required — from ffmpeg 8 the encoder reads color properties off the FRAMES, silently overriding the container flags, so a flags-only output decodes washed-out. `buildTrimConcatArgs` takes the filter as its `colorTagFilter` option rather than probing, to stay pure. `installEncodedVideo(tmpPath, targetPath, label)` is the shared in-place install: move the original aside to a `.bak` on Windows (where `fs.rename` refuses an existing destination), rename the new file over it, and restore the backup — plus unlink the temp — on any failure, returning `{ok:true,outPath}` / `{ok:false,reason}` so the worst case is "skipped", never "the video is gone". Use it for EVERY replace-a-video-with-its-re-encode path; `pipeline/audioMux.js` is the out-of-module caller. `edgeFadeFilter(durationSec)` is the `-af` fade-in/fade-out fragment a mid-song clip (a social cut) appends to its trim. Loudness mastering (#10249): `MASTER_LOUDNESS` (-14 LUFS / -1.5 dBTP / LRA 11), `planLoudnessMaster` (measure then build the linear apply filter; throws on a silent source), `reportMasteredLoudness` (post-encode before/after numbers). |+| `ffmpeg.js` | Shared ffmpeg helpers (videoGen + videoTimeline). `vfrSyncArgs(bin)` probes/caches supported VFR output flags per binary (fps_mode on current builds, vsync on older builds); inconclusive probes stay uncached. `probeVideoGeometry(videoPath)` measures a finished clip's `{ width, height, fps, numFrames, durationSec }` (null when any axis is unreadable) for hosted renders that record no frame count. `generateThumbnail(videoPath, jobId, { atSec } = {})` accepts a clamped poster seek while preserving the single-clip default. Includes `probeFrameCount(videoPath)` (metadata `nb_frames`, falling back to a real `-count_frames` pass — expensive, so call it once per file) and `trimVideoFromFrame(videoPath, outPath, {startFrame, fps})` — a frame-EXACT head cut via the `trim` filter (an `-ss` seek can drift a frame, which reads as a stutter at a stitch seam), keeping audio in sync with `atrim` when the clip has a soundtrack and taking `-an` when it doesn't. Re-encodes by necessity, so a later concat must re-encode too; `outPath` may equal the input (temp-file + rename install). Used by the chained-render context window — see `videoContinuity.js`. `buildTrimConcatArgs({inputs, outPath, width, height, fps, withAudio})` builds the argv for the other half of that job: a concat that drops leading frames from some of its inputs inside a `filter_complex` graph, so the cuts ride along with the timeline encode instead of costing one pre-encode per clip (pass `withAudio` only when EVERY input has an audio stream — check with `hasAudioStream`). `buildExtendSpliceArgs({sourcePath, generatedPath, outPath, keepFrames, newStartFrame, width, height, fps, audio, sourceAudioPath, masterOutPath})` is the plain-Extend counterpart: source frames `[0, keep)` + render frames from `newStartFrame`, one encode, audio crossfaded (~40 ms linear) at the seam; `sourceAudioPath` swaps the source span's audio for a lossless master and `masterOutPath` also writes the mix as a 24-bit FLAC master, so the delivered AAC is encoded once from PCM. Its stream-copy sibling is `buildExtendNewSpanArgs` (encode only the render's new span) + `buildExtendConcatList` + `buildExtendCopyArgs` (join it to the untouched source with `-c:v copy`); `probeVideoCodecSignature` gates it and `videoFrameHashes` (per-frame MD5) proves the join before anything is replaced; `audioFingerprint` / `sealAudioMaster` / `readAudioMasterFingerprint` bind a master to the exact decoded soundtrack it was mixed for so a replaced soundtrack invalidates it — driven by `services/videoGen/extendSplice.js`. `H264_ENCODE_ARGS` / `AAC_ENCODE_ARGS` are the shared encode profile: clips produced by different paths here get concatenated together, so a mismatch shows up as one segment graded differently from its neighbours — spread these rather than re-typing the flags. Every re-encode here also pins BT.709: `BT709_CONTAINER_ARGS` (the `colr` atom, always emitted) plus `bt709TagFilter()` → the `BT709_TAG_FILTER` `setparams=…` string, or `null` on an ffmpeg without that filter (`supportsSetparamsFilter()` probes `-filters` once per process; `null` = not probed, and a probe that couldn't run stays uncached). Both halves are required — from ffmpeg 8 the encoder reads color properties off the FRAMES, silently overriding the container flags, so a flags-only output decodes washed-out. `buildTrimConcatArgs` takes the filter as its `colorTagFilter` option rather than probing, to stay pure. `installEncodedVideo(tmpPath, targetPath, label)` is the shared in-place install: move the original aside to a `.bak` on Windows (where `fs.rename` refuses an existing destination), rename the new file over it, and restore the backup — plus unlink the temp — on any failure, returning `{ok:true,outPath}` / `{ok:false,reason}` so the worst case is "skipped", never "the video is gone". Use it for EVERY replace-a-video-with-its-re-encode path; `pipeline/audioMux.js` is the out-of-module caller. `edgeFadeFilter(durationSec)` is the `-af` fade-in/fade-out fragment a mid-song clip (a social cut) appends to its trim. Loudness mastering (#10249): `MASTER_LOUDNESS` (-14 LUFS / -1.5 dBTP / LRA 11), `planLoudnessMaster` (measure then build the linear apply filter; throws on a silent source), `reportMasteredLoudness` (post-encode before/after numbers). || `ffmpegFilterGraph.js` | `filterGraphViaFile(bin, args, path)` moves a `-filter_complex` graph over `FILTER_GRAPH_ARG_LIMIT` into a file (`-/filter_complex`, or `-filter_complex_script` before ffmpeg 7), since Linux and Windows cap argument length. Used by the music video render and excerpt encodes. || `forgeAccessErrors.js` | `isForgeNoAccessError(err)` / `isForgeNoAccessMessage(text)` / `logForgeNoAccessOnce(scope, repoSpec, detail)` / `forgeNoAccessRemedy(repoSpec)` — tells a PERMANENT `gh` no-access 404 (`Could not resolve to a Repository`, `HTTP 404`) apart from a transient blip. `execGh` stamps `ghNoAccess` on the rejection and keeps it OUT of the consecutive-failure backoff (which caps at 15 min and then re-fires forever), and the polling jobs (`branchReconcile`, `prWatcher`) narrate it exactly once per scope+repo per process with a remedy line instead of once per tick. `__resetForgeNoAccessLog()` is the test seam. || `forkHead.js` | `normalizeForkHead(value)` / `forkRemoteName(ownerLogin)` / `resolveTaskForkHead(metadata)` — the validated `{remoteUrl, ownerLogin}` address of a cross-repository PR's head branch, which has no `origin/<branch>` to attach to. Fail-closed: anything that isn't a usable pair (or that starts with `-`, which git would read as an option) is `null`, so every caller falls back to origin-only behavior instead of guessing. `forkRemoteName` is the deterministic `fork-<owner>` remote name that makes a re-attach reuse the remote it already added. Shared by `appPullRequests.js` (produces), `agentWorktreeCleanup.js`/`prRemediationFollowUp.js` (persist in task metadata), `agentWorkspacePrep.js` (threads), and `worktreeManager.js` (consumes — it has no forge client of its own). `resolveTaskForkHead` is the single reader of the generic `forkHead` task-metadata key, the fork-side counterpart to `taskTargetBranch.js`. |diff --git a/server/lib/ffmpeg.frameExtraction.test.js b/server/lib/ffmpeg.frameExtraction.test.jsnew file mode 100644index 0000000000..de9eb8c6bb--- /dev/null+++ b/server/lib/ffmpeg.frameExtraction.test.js@@ -0,0 +1,105 @@+import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';+import { mkdir, readFile, readdir } from 'node:fs/promises';+import { join } from 'node:path';+import { randomUUID } from 'node:crypto';+import sharp from 'sharp';+import { cleanupTempDataRoots, lazyTempDataRoot, makePathsProxy } from './mockPathsDataRoot.js';++const state = vi.hoisted(() => ({ history: [], candidates: [], picked: null }));+vi.mock('./fileUtils.js', async original => makePathsProxy(await original(), {+ dataRoot: () => lazyTempDataRoot('portos-frame-sync-'),+}));+vi.mock('../services/videoGen/history.js', () => ({ loadHistory: async () => state.history }));+vi.mock('./frameQuality.js', async original => {+ const actual = await original();+ const { default: image } = await import('sharp');+ return { ...actual, pickBestFrame: async paths => {+ // Observe the real decoded candidates before the service removes its temp+ // directory; ranking itself remains the production implementation.+ state.candidates = await Promise.all(paths.map(async path => (await image(path).stats()).channels[0].mean));+ state.picked = await actual.pickBestFrame(paths);+ return state.picked;+ } };+});++import { PATHS } from './fileUtils.js';+import { findFfmpeg, findFfprobe, runFfmpegProcess, extractEvaluationFrames, probeFrameCount } from './ffmpeg.js';+import { encodeFileContactSheetAtTimes } from '../services/htmlComposition/encode.js';+import { extractLastFrame } from '../services/videoGen/frameExtraction.js';++const ffmpeg = await findFfmpeg();+const ffprobe = await findFfprobe();+const level = index => 24 + index * 3;+const frameIndex = mean => (mean - 24) / 3;++describe.skipIf(!ffmpeg || !ffprobe)('frame extraction over native FFmpeg and synthetic media', () => {+ let video;+ beforeAll(async () => {+ await mkdir(PATHS.videos, { recursive: true });+ const frames = join(PATHS.videos, 'source');+ await mkdir(frames);+ // A lossless, 30 fps, two-second clip. Each frame's gray level names its+ // index; the checkerboard gives the real anchor scorer usable detail.+ await Promise.all(Array.from({ length: 60 }, async (_, index) => {+ const pixels = Buffer.alloc(32 * 32 * 3);+ for (let y = 0; y < 32; y++) for (let x = 0; x < 32; x++) {+ const value = level(index) + ((x + y) % 2 ? 12 : -12);+ pixels.fill(value, (y * 32 + x) * 3, (y * 32 + x + 1) * 3);+ }+ await sharp(pixels, { raw: { width: 32, height: 32, channels: 3 } }).png()+ .toFile(join(frames, `${String(index + 1).padStart(3, '0')}.png`));+ }));+ video = join(PATHS.videos, 'synthetic.mkv');+ const made = await runFfmpegProcess({ bin: ffmpeg, args: ['-hide_banner', '-loglevel', 'error',+ '-framerate', '30', '-i', join(frames, '%03d.png'), '-c:v', 'ffv1', '-pix_fmt', 'bgr0', '-y', video] });+ expect(made).toMatchObject({ ok: true });+ expect(await probeFrameCount(video)).toBe(60);+ }, 30000);+ afterAll(cleanupTempDataRoots);++ it('tiles exact sparse boundary frames once and leaves a duplicate-time cell padded', async () => {+ const output = join(PATHS.videos, 'sheet.png');+ expect(await encodeFileContactSheetAtTimes(video, output, [0, 1 / 30, 0.034, 0.5, 59 / 30], { fps: 30 }))+ .toEqual({ columns: 5, rows: 1 });+ const image = sharp(output);+ expect(await image.metadata()).toMatchObject({ width: 1816, height: 360 });+ for (const [cell, index] of [0, 1, 15, 59].entries()) {+ const pixels = await image.clone().extract({ left: cell * 364, top: 0, width: 360, height: 360 }).toBuffer();+ const mean = (await sharp(pixels).stats()).channels[0].mean;+ expect(mean).toBeCloseTo(level(index), 0);+ }+ const padded = await sharp(await image.clone().extract({ left: 4 * 364, top: 0, width: 360, height: 360 }).toBuffer()).stats();+ expect(padded.channels[0].max).toBe(0);+ });++ it('extracts five ordered quartile frames without padding and only three from a tiny clip', async () => {+ const names = await extractEvaluationFrames(video, 'quartile', 5);+ expect(names).toHaveLength(5);+ expect((await readdir(PATHS.videoThumbnails)).filter(name => name.startsWith('quartile-'))).toHaveLength(5);+ for (const [i, index] of [0, 15, 30, 44, 59].entries()) {+ const mean = (await sharp(join(PATHS.videoThumbnails, names[i])).stats()).channels[0].mean;+ expect(Math.abs(frameIndex(mean) - index)).toBeLessThan(0.5);+ }+ const tiny = join(PATHS.videos, 'tiny.mkv');+ expect(await runFfmpegProcess({ bin: ffmpeg, args: ['-i', video, '-frames:v', '3', '-c:v', 'copy', '-y', tiny] }))+ .toMatchObject({ ok: true });+ const short = await extractEvaluationFrames(tiny, 'tiny', 5);+ expect(short).toHaveLength(3);+ expect((await readdir(PATHS.videoThumbnails)).filter(name => name.startsWith('tiny-'))).toHaveLength(3);+ });++ it('decodes the twelve tail candidates at the original sampling times and records the selected offset', async () => {+ const id = randomUUID();+ state.history = [{ id, filename: 'synthetic.mkv', prompt: 'Synthetic frame grid' }];+ const anchor = await extractLastFrame(id);+ expect(state.candidates).toHaveLength(12);+ for (const [i, mean] of state.candidates.entries()) {+ expect(Math.abs(frameIndex(mean) - (30 + i * 30 / 12))).toBeLessThanOrEqual(1);+ }+ expect(state.picked).not.toBeNull();+ const installed = (await sharp(join(PATHS.images, anchor.filename)).stats()).channels[0].mean;+ expect(installed).toBeCloseTo(state.candidates[state.picked.index], 5);+ const metadata = JSON.parse(await readFile(join(PATHS.images, anchor.filename.replace('.png', '.metadata.json')), 'utf8'));+ expect(metadata.extractedAt).toBe(`-${((12 - state.picked.index) / 12).toFixed(2)}s`);+ });+});diff --git a/server/lib/ffmpeg.frameSync.test.js b/server/lib/ffmpeg.frameSync.test.jsnew file mode 100644index 0000000000..2130d5824f--- /dev/null+++ b/server/lib/ffmpeg.frameSync.test.js@@ -0,0 +1,34 @@+import { describe, expect, it, vi } from 'vitest';++const { probe } = vi.hoisted(() => ({ probe: vi.fn() }));+vi.mock('./childProcess.js', async original => ({+ ...await original(),+ execFile: Object.assign(() => {}, { [Symbol.for('nodejs.util.promisify.custom')]: probe }),+}));+import { vfrSyncArgs } from './ffmpeg.js';++describe('VFR output synchronization capability', () => {+ it('uses the current per-output option, sharing one probe across concurrent callers', async () => {+ probe.mockResolvedValueOnce({ stdout: '-fps_mode[:stream_specifier] set framerate mode\n-vsync old sync option' });+ const before = probe.mock.calls.length;+ expect(await Promise.all([vfrSyncArgs('current'), vfrSyncArgs('current')]))+ .toEqual([['-fps_mode', 'vfr'], ['-fps_mode', 'vfr']]);+ expect(await vfrSyncArgs('current')).toEqual(['-fps_mode', 'vfr']);+ expect(probe.mock.calls.length - before).toBe(1);+ expect(probe.mock.calls.at(-1)[1]).toEqual(['-hide_banner', '-h', 'full']);+ });++ it('preserves older builds that advertise only the legacy VFR option', async () => {+ probe.mockResolvedValueOnce({ stdout: ' -vsync video sync method' });+ expect(await vfrSyncArgs('legacy')).toEqual(['-vsync', 'vfr']);+ expect(await vfrSyncArgs('current')).toEqual(['-fps_mode', 'vfr']);+ });++ it.each(['failure', 'unrecognized help'])('does not cache an inconclusive %s as an old build', async kind => {+ if (kind === 'failure') probe.mockRejectedValueOnce(new Error('temporary probe failure'));+ else probe.mockResolvedValueOnce({ stdout: 'usage without an option listing' });+ expect(await vfrSyncArgs(kind)).toEqual(['-fps_mode', 'vfr']);+ probe.mockResolvedValueOnce({ stdout: '-vsync video sync method' });+ expect(await vfrSyncArgs(kind)).toEqual(['-vsync', 'vfr']);+ });+});diff --git a/server/lib/ffmpeg.js b/server/lib/ffmpeg.jsindex addd33eee8..22f6b24141 100644--- a/server/lib/ffmpeg.js+++ b/server/lib/ffmpeg.js@@ -47,6 +47,31 @@ export const findFfmpeg = async () => {return found;};+const vfrSyncProbes = new Map();+const CURRENT_VFR_ARGS = Object.freeze(['-fps_mode', 'vfr']);+const LEGACY_VFR_ARGS = Object.freeze(['-vsync', 'vfr']);++// fps_mode replaced the global vsync option in 5.1; 9 removes vsync. Probe+// capabilities rather than imposing a new version floor on older installs.+// Like the setparams probe below, an inconclusive result stays uncached.+export const vfrSyncArgs = async (bin) => {+ if (vfrSyncProbes.has(bin)) return vfrSyncProbes.get(bin);+ const probe = execFileAsync(bin, ['-hide_banner', '-h', 'full'], safeChildProcessOptions({+ timeout: 5000, maxBuffer: 4 * 1024 * 1024,+ })).then(({ stdout }) => {+ const listing = String(stdout || '');+ if (/^\s*-fps_mode(?:\s|\[|$)/m.test(listing)) return CURRENT_VFR_ARGS;+ if (/^\s*-vsync(?:\s|$)/m.test(listing)) return LEGACY_VFR_ARGS;+ vfrSyncProbes.delete(bin);+ return CURRENT_VFR_ARGS;+ }, () => {+ vfrSyncProbes.delete(bin);+ return CURRENT_VFR_ARGS;+ });+ vfrSyncProbes.set(bin, probe);+ return probe;+};+/*** Spawn an ffmpeg child process and resolve with a structured result.* Collapses three sibling implementations (audioMux mux, optimizeForStreaming@@ -475,14 +500,14 @@ export const extractEvaluationFrames = async (videoPath, jobId, count = 5) => {// Filter expression: select frames matching any of the target indices.// Single-quoting the expression lets ffmpeg's filter parser treat the// commas inside `eq(n,X)` as expression args rather than filter-chain- // separators. `-vsync vfr` prevents the image2 muxer from padding output+ // separators. VFR sync prevents the image2 muxer from padding output// to maintain input fps (which would re-emit each match repeatedly).const selectExpr = frameIndices.map((i) => `eq(n,${i})`).join('+');const outPattern = join(PATHS.videoThumbnails, `${jobId}-f%d.jpg`);const result = await runFfmpegProcess({bin: ffmpeg,- args: ['-i', videoPath, '-vf', `select='${selectExpr}'`, '-vsync', 'vfr', '-q:v', '5', '-y', outPattern],+ args: ['-i', videoPath, '-vf', `select='${selectExpr}'`, ...await vfrSyncArgs(ffmpeg), '-q:v', '5', '-y', outPattern],stderrTailBytes: 0,});if (!result.ok && result.reason?.startsWith('spawn failed: ')) {diff --git a/server/services/htmlComposition/encode.js b/server/services/htmlComposition/encode.jsindex 5e93bbc28b..e19d8668ed 100644--- a/server/services/htmlComposition/encode.js+++ b/server/services/htmlComposition/encode.js@@ -6,7 +6,7 @@ import { availableParallelism, totalmem } from 'node:os';import { rm, writeFile } from 'node:fs/promises';import sharp from 'sharp';import { blurFrame } from './shutterBlur.js';-import { findFfmpeg, runFfmpegProcess, probeVideoDuration, H264_ENCODE_ARGS, AAC_ENCODE_ARGS, BT709_CONTAINER_ARGS, bt709TagFilter, planLoudnessMaster, reportMasteredLoudness } from '../../lib/ffmpeg.js';+import { findFfmpeg, runFfmpegProcess, probeVideoDuration, vfrSyncArgs, H264_ENCODE_ARGS, AAC_ENCODE_ARGS, BT709_CONTAINER_ARGS, bt709TagFilter, planLoudnessMaster, reportMasteredLoudness } from '../../lib/ffmpeg.js';// Size the viewport for this format, then let the composition reframe itself// (#8960) before any seek captures it. A composition without a layout hook@@ -452,7 +452,7 @@ export async function encodeFileContactSheetAtTimes(videoPath, outputPath, timesbin: ffmpeg,args: ['-hide_banner', '-loglevel', 'error', '-i', videoPath, '-vf',`select='${selectExpr}',scale=${tileWidth}:-2,tile=${columns}x${rows}:padding=4:color=black`,- '-vsync', 'vfr', '-frames:v', '1', '-y', outputPath],+ ...await vfrSyncArgs(ffmpeg), '-frames:v', '1', '-y', outputPath],});if (!result.ok) throw new Error(`Excerpt contact sheet failed: ${result.reason}`);return { columns, rows };diff --git a/server/services/videoGen/frameExtraction.js b/server/services/videoGen/frameExtraction.jsindex 8022f2b05e..08166d7712 100644--- a/server/services/videoGen/frameExtraction.js+++ b/server/services/videoGen/frameExtraction.js@@ -7,7 +7,7 @@ import { spawn } from '../../lib/childProcess.js';import { ensureDir, PATHS, UUID_RE, tryReadFile, copyFileGuarded, writeFileGuarded, unlinkGuarded, rmGuarded } from '../../lib/fileUtils.js';import { ServerError } from '../../lib/errorHandler.js';import {- findFfmpeg, safeUnder, extractEvaluationFrames, runFfmpegProcess,+ findFfmpeg, safeUnder, extractEvaluationFrames, runFfmpegProcess, vfrSyncArgs,} from '../../lib/ffmpeg.js';import {TAIL_WINDOW_SECONDS, CANDIDATE_FPS, MAX_CANDIDATES, pickBestFrame,@@ -41,7 +41,7 @@ async function decodeTailCandidates(ffmpeg, videoPath, candidateDir) {bin: ffmpeg,args: ['-sseof', `-${TAIL_WINDOW_SECONDS.toFixed(2)}`, '-i', videoPath,- '-vf', `fps=${CANDIDATE_FPS}`, '-vsync', 'vfr',+ '-vf', `fps=${CANDIDATE_FPS}`, ...await vfrSyncArgs(ffmpeg),'-frames:v', String(MAX_CANDIDATES), '-y', outPattern,],stderrTailBytes: 0,diff --git a/server/services/videoGen/local.test.js b/server/services/videoGen/local.test.jsindex d0abd76847..665c54ffa4 100644--- a/server/services/videoGen/local.test.js+++ b/server/services/videoGen/local.test.js@@ -266,6 +266,7 @@ const probeMockImpl = vi.hoisted(() => ({vi.mock('../../lib/ffmpeg.js', async () => ({findFfmpeg: vi.fn(async () => '/usr/bin/ffmpeg'),+ vfrSyncArgs: vi.fn(async () => ['-fps_mode', 'vfr']),safeUnder: vi.fn((base, file) => (file ? join(base, file) : null)),generateThumbnail: vi.fn(async () => 'thumb.jpg'),optimizeForStreaming: vi.fn(async () => {}),