Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

Keep downloaded clips over 20 MB when they are not joined

Claude5a884f3277f1
diff --git a/docs/providers-and-models.md b/docs/providers-and-models.md
index 8a650c752..3fc64fdc3 100644
--- a/docs/providers-and-models.md
+++ b/docs/providers-and-models.md
@@ -333,7 +333,7 @@ scene at a length the model offers (a scene longer than its longest clip is
refused, so the agent splits it into scenes with their own prompts), generates
up to three clips at a time with one retry each (none when the provider refuses
the request, such as for lack of credit, or returns a clip that is not an MP4),
-downloads hosted clips without the API key, and joins them into one MP4
+downloads hosted clips (up to 160 MB each) without the API key, and joins them into one MP4
without re-encoding (`src/*/src/agent/video-join.js`, which parses
the clips with the vendored mp4box.js). A clip's sound often ends a little
before its picture or starts after it; with AAC-LC sound (the usual MP4 audio,
diff --git a/src/chrome/src/agent/generative-media.js b/src/chrome/src/agent/generative-media.js
index f1d05ce23..24f7b8fe1 100644
--- a/src/chrome/src/agent/generative-media.js
+++ b/src/chrome/src/agent/generative-media.js
@@ -763,7 +763,8 @@ async function storeVideoClips(clips, onProgress) {
}
const stored = [];
for (const bytes of clips) {
- const asset = await storeGeneratedMediaBlob(new Blob([bytes], { type: 'video/mp4' }));
+ // A clip may be as large as a joined video: hosted clips are downloaded up to that size.
+ const asset = await storeGeneratedMediaBlob(new Blob([bytes], { type: 'video/mp4' }), { maxBytes: MAX_JOINED_VIDEO_BYTES });
stored.push({ mediaId: asset.mediaId, mimeType: asset.mimeType, durationSeconds: roundSeconds(mp4DurationSeconds(bytes)) });
}
const durationSeconds = roundSeconds(stored.reduce((sum, clip) => sum + (clip.durationSeconds || 0), 0));
diff --git a/src/chrome/src/generated-media-store.js b/src/chrome/src/generated-media-store.js
index 3ef3b11cb..2be70847e 100644
--- a/src/chrome/src/generated-media-store.js
+++ b/src/chrome/src/generated-media-store.js
@@ -24,7 +24,7 @@ export async function storeGeneratedMedia(dataUrl) {
return storeGeneratedMediaBlob(new Blob([bytes], { type: match[1] }));
}
-// `maxBytes` above 20 MB is for a joined video only.
+// `maxBytes` above 20 MB is for videos: one joined from clips, or a clip of one.
export async function storeGeneratedMediaBlob(blob, { maxBytes = MAX_BYTES } = {}) {
if (!(blob instanceof Blob) || !MEDIA_MIME.test(blob.type)) throw new Error('Unsupported generated media.');
const limit = Math.min(maxBytes, blob.type === 'video/mp4' ? MAX_JOINED_VIDEO_BYTES : MAX_BYTES);
diff --git a/src/firefox/src/agent/generative-media.js b/src/firefox/src/agent/generative-media.js
index f1d05ce23..24f7b8fe1 100644
--- a/src/firefox/src/agent/generative-media.js
+++ b/src/firefox/src/agent/generative-media.js
@@ -763,7 +763,8 @@ async function storeVideoClips(clips, onProgress) {
}
const stored = [];
for (const bytes of clips) {
- const asset = await storeGeneratedMediaBlob(new Blob([bytes], { type: 'video/mp4' }));
+ // A clip may be as large as a joined video: hosted clips are downloaded up to that size.
+ const asset = await storeGeneratedMediaBlob(new Blob([bytes], { type: 'video/mp4' }), { maxBytes: MAX_JOINED_VIDEO_BYTES });
stored.push({ mediaId: asset.mediaId, mimeType: asset.mimeType, durationSeconds: roundSeconds(mp4DurationSeconds(bytes)) });
}
const durationSeconds = roundSeconds(stored.reduce((sum, clip) => sum + (clip.durationSeconds || 0), 0));
diff --git a/src/firefox/src/generated-media-store.js b/src/firefox/src/generated-media-store.js
index 3ef3b11cb..2be70847e 100644
--- a/src/firefox/src/generated-media-store.js
+++ b/src/firefox/src/generated-media-store.js
@@ -24,7 +24,7 @@ export async function storeGeneratedMedia(dataUrl) {
return storeGeneratedMediaBlob(new Blob([bytes], { type: match[1] }));
}
-// `maxBytes` above 20 MB is for a joined video only.
+// `maxBytes` above 20 MB is for videos: one joined from clips, or a clip of one.
export async function storeGeneratedMediaBlob(blob, { maxBytes = MAX_BYTES } = {}) {
if (!(blob instanceof Blob) || !MEDIA_MIME.test(blob.type)) throw new Error('Unsupported generated media.');
const limit = Math.min(maxBytes, blob.type === 'video/mp4' ? MAX_JOINED_VIDEO_BYTES : MAX_BYTES);
diff --git a/test/generative-media-video.mjs b/test/generative-media-video.mjs
index 32cf57f50..f7c31b3ec 100644
--- a/test/generative-media-video.mjs
+++ b/test/generative-media-video.mjs
@@ -705,6 +705,24 @@ for (const build of ['chrome', 'firefox']) {
assert.equal(single.url, 'https://v3b.fal.media/files/b/clip-0.mp4');
});
+ test(`${build}: a hosted clip larger than 20 MB is kept when it is not joined`, async () => {
+ // A valid clip padded past 20 MB with a top-level free box.
+ const size = 21 * 1024 * 1024;
+ const large = new Uint8Array(fixtures['h264-aac-1'].length + size);
+ large.set(fixtures['h264-aac-1']);
+ new DataView(large.buffer).setUint32(fixtures['h264-aac-1'].length, size);
+ large.set([0x66, 0x72, 0x65, 0x65], fixtures['h264-aac-1'].length + 4);
+ // One scene is stored as it is; two that cannot be joined are stored one by one.
+ for (const [count, clip] of [[1, () => large], [2, index => (index ? fixtures['h264-aac-48px'] : large)]]) {
+ const api = falApi({ model: h3Max.id, schema: h3Max.schema, clip });
+ const result = await generate({ prompt: 'Story', scenes: scenes(count, 10), estimated_duration: 10 * count },
+ { config: falConfig(h3Max), fetchImpl: api.fetchImpl, pollIntervalMs: 1 });
+ assert.equal(result.success, true, result.error);
+ assert.equal(result.clipCount, count);
+ assert.deepEqual(await storedBytes(count === 1 ? result.mediaId : result.clips[0].mediaId), large);
+ }
+ });
+
test(`${build}: fal.ai lengths are sent the way the model lists them`, async () => {
const run = async (model, video) => {
const api = falApi({ model: model.id, schema: model.schema });