The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.
Look: open-ended media ranges are at most 2 MiB, and a frame-duration lookup given up on is not a problem (#210)
philipp-reisichcb731fd9acd7
diff --git a/.changeset/look-many-videos-awake.md b/.changeset/look-many-videos-awake.mdnew file mode 100644index 0000000..fc9b060--- /dev/null+++ b/.changeset/look-many-videos-awake.md@@ -0,0 +1,5 @@+---+"openfilm": patch+---++`look` and `render` keep going when more than six videos of long files are awake at once: an open-ended read of a video is at most 2 MiB, so a paused video reads its piece to the end and holds no connection, and a frame-duration lookup given up on after ten seconds is no longer reported as a failed request.diff --git a/packages/openfilm/src/host.mjs b/packages/openfilm/src/host.mjsindex 6c5d197..4fa337a 100644--- a/packages/openfilm/src/host.mjs+++ b/packages/openfilm/src/host.mjs@@ -132,11 +132,13 @@ export function folderFiles(root, { inject = `<script>${HOST_FLAG}</script>`, ti/* A cancelled preview is normal: pipeline closes its file; its callback deliberately ignores the error. */const range = /^bytes=(\d*)-(\d*)$/.exec(req.headers.range ?? '');if (range && (range[1] || range[2])) {- /* `bytes=-500` is the last 500 bytes. An open end (`bytes=X-`) is at most the next 8 MiB: one response must+ /* `bytes=-500` is the last 500 bytes. An open end (`bytes=X-`) is at most the next 2 MiB: one response mustnot hold a connection for the rest of a long file. A browser keeps six HTTP/1.1 connections to a host, and- a frame's duration lookup waits behind them until one is free. */+ a frame's duration lookup waits behind them until one is free. A paused video stops reading once it has+ buffered enough and leaves the rest of its piece unread: pieces of 8 MiB still held all six with more than+ six videos awake; pieces of 2 MiB are read to their end. */const start = range[1] ? Number(range[1]) : Math.max(0, stat.size - Number(range[2]));- const end = range[1] && !range[2] ? Math.min(start + 8 * 1024 * 1024 - 1, stat.size - 1)+ const end = range[1] && !range[2] ? Math.min(start + 2 * 1024 * 1024 - 1, stat.size - 1): range[1] && range[2] ? Math.min(Number(range[2]), stat.size - 1) : stat.size - 1;if (start > end || start >= stat.size) { res.writeHead(416, { ...headers, 'content-range': `bytes */${stat.size}` }).end(); return true; }res.writeHead(206, { ...headers, 'content-range': `bytes ${start}-${end}/${stat.size}`, 'content-length': end - start + 1 });@@ -402,6 +404,7 @@ export class FilmPage {const why = r.failure()?.errorText ?? 'failed';if (why === 'net::ERR_ABORTED' && r.resourceType() === 'media') return; // media elements cancel range requests routinelyif (why === 'net::ERR_ABORTED' && r.method() === 'HEAD') return; // a file's presence asked (timeline.mjs): its status is the answer+ if (why === 'net::ERR_ABORTED' && new URL(r.url()).pathname.endsWith('/__film/frame-duration')) return; // given up on after 10 s (timeline.mjs frameOf): the frame is drawn from the guessif (why === 'net::ERR_BLOCKED_BY_CLIENT') return; // reported by the offline route with its reasonproblems.push({ kind: 'request', message: `${why} ${r.url()}` });});diff --git a/packages/openfilm/src/host.test.mjs b/packages/openfilm/src/host.test.mjsindex 46977c9..4a40407 100644--- a/packages/openfilm/src/host.test.mjs+++ b/packages/openfilm/src/host.test.mjs@@ -61,8 +61,8 @@ test('cancelled media requests close their files so the project can be renamed',}});-test('an open-ended media range returns at most 8 MiB', async () => {- const cap = 8 * 1024 * 1024;+test('an open-ended media range returns at most 2 MiB', async () => {+ const cap = 2 * 1024 * 1024;const dir = mkdtempSync(join(tmpdir(), 'of-host-range-'));const data = Buffer.alloc(cap + 2, '0123456789');writeFileSync(join(dir, 'video.mp4'), data);diff --git a/packages/openfilm/src/timeline.test.mjs b/packages/openfilm/src/timeline.test.mjsindex 9c70ca2..105d467 100644--- a/packages/openfilm/src/timeline.test.mjs+++ b/packages/openfilm/src/timeline.test.mjs@@ -1086,3 +1086,23 @@ test('an exact frame is drawn when the frame duration never answers', { skip: !hrmSync(dir, { recursive: true, force: true });}});++test('a frame-duration lookup given up on is not a problem: the frame is drawn from the guess', { skip: !hasFfmpeg && 'no ffmpeg', timeout: 40_000 }, async () => {+ const dir = footage('of-duration-held-');+ writeFileSync(join(dir, 'film.html'), filmHtml({ stage: { w: 320, h: 180 }, tracks: [{ clips: [{ id: 'v', src: 'a.mp4', time: [0, 4] }] }] }));+ const s = await open(dir);+ try {+ /* held, never answered: frameOf gives it up after 10 s */+ await s.film.page.route('**/__film/frame-duration?*', () => {});+ const given = s.film.page.waitForEvent('requestfailed', {+ predicate: (request) => new URL(request.url()).pathname.endsWith('/__film/frame-duration'), timeout: 25_000,+ });+ await Promise.all([s.film.seek(0.4), given]);+ const [video] = await videosNow(s.film);+ assert.ok(video.shown && video.ready && Math.abs(video.time - 0.4) < 0.01, JSON.stringify(video));+ assert.deepEqual(s.film.problems, []);+ } finally {+ await s.close();+ rmSync(dir, { recursive: true, force: true });+ }+});