@shotstack/shotstack-canvas 1.5.7 → 1.5.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2318,16 +2318,29 @@ var VideoGenerator = class {
2318
2318
  });
2319
2319
  try {
2320
2320
  const painter = await createNodePainter({ width, height, pixelRatio });
2321
- for (let frame = 0; frame < totalFrames; frame++) {
2322
- const t = frame / (totalFrames - 1) * duration;
2323
- const ops = await frameGenerator(t);
2324
- await painter.render(ops);
2325
- const png = await painter.toPNG();
2326
- const ok = ffmpeg.stdin.write(png);
2327
- if (!ok) await new Promise((r) => ffmpeg.stdin.once("drain", r));
2328
- if (frame % Math.max(1, Math.floor(fps / 2)) === 0) {
2329
- const pct = Math.round((frame + 1) / totalFrames * 100);
2330
- console.log(`\u{1F39E}\uFE0F Rendering frames: ${pct}%`);
2321
+ const CHUNK_SIZE = 30;
2322
+ for (let chunkStart = 0; chunkStart < totalFrames; chunkStart += CHUNK_SIZE) {
2323
+ const chunkEnd = Math.min(chunkStart + CHUNK_SIZE, totalFrames);
2324
+ const chunkSize = chunkEnd - chunkStart;
2325
+ const chunkOps = [];
2326
+ for (let frame = chunkStart; frame < chunkEnd; frame++) {
2327
+ const t = frame / (totalFrames - 1) * duration;
2328
+ chunkOps.push(await frameGenerator(t));
2329
+ }
2330
+ for (let i = 0; i < chunkSize; i++) {
2331
+ const frame = chunkStart + i;
2332
+ await painter.render(chunkOps[i]);
2333
+ const png = await painter.toPNG();
2334
+ const ok = ffmpeg.stdin.write(png);
2335
+ if (!ok) await new Promise((r) => ffmpeg.stdin.once("drain", r));
2336
+ if (frame % Math.max(1, Math.floor(fps / 2)) === 0) {
2337
+ const pct = Math.round((frame + 1) / totalFrames * 100);
2338
+ console.log(`\u{1F39E}\uFE0F Rendering frames: ${pct}%`);
2339
+ }
2340
+ }
2341
+ chunkOps.length = 0;
2342
+ if (global.gc && chunkEnd < totalFrames) {
2343
+ global.gc();
2331
2344
  }
2332
2345
  }
2333
2346
  ffmpeg.stdin.end();
@@ -2279,16 +2279,29 @@ var VideoGenerator = class {
2279
2279
  });
2280
2280
  try {
2281
2281
  const painter = await createNodePainter({ width, height, pixelRatio });
2282
- for (let frame = 0; frame < totalFrames; frame++) {
2283
- const t = frame / (totalFrames - 1) * duration;
2284
- const ops = await frameGenerator(t);
2285
- await painter.render(ops);
2286
- const png = await painter.toPNG();
2287
- const ok = ffmpeg.stdin.write(png);
2288
- if (!ok) await new Promise((r) => ffmpeg.stdin.once("drain", r));
2289
- if (frame % Math.max(1, Math.floor(fps / 2)) === 0) {
2290
- const pct = Math.round((frame + 1) / totalFrames * 100);
2291
- console.log(`\u{1F39E}\uFE0F Rendering frames: ${pct}%`);
2282
+ const CHUNK_SIZE = 30;
2283
+ for (let chunkStart = 0; chunkStart < totalFrames; chunkStart += CHUNK_SIZE) {
2284
+ const chunkEnd = Math.min(chunkStart + CHUNK_SIZE, totalFrames);
2285
+ const chunkSize = chunkEnd - chunkStart;
2286
+ const chunkOps = [];
2287
+ for (let frame = chunkStart; frame < chunkEnd; frame++) {
2288
+ const t = frame / (totalFrames - 1) * duration;
2289
+ chunkOps.push(await frameGenerator(t));
2290
+ }
2291
+ for (let i = 0; i < chunkSize; i++) {
2292
+ const frame = chunkStart + i;
2293
+ await painter.render(chunkOps[i]);
2294
+ const png = await painter.toPNG();
2295
+ const ok = ffmpeg.stdin.write(png);
2296
+ if (!ok) await new Promise((r) => ffmpeg.stdin.once("drain", r));
2297
+ if (frame % Math.max(1, Math.floor(fps / 2)) === 0) {
2298
+ const pct = Math.round((frame + 1) / totalFrames * 100);
2299
+ console.log(`\u{1F39E}\uFE0F Rendering frames: ${pct}%`);
2300
+ }
2301
+ }
2302
+ chunkOps.length = 0;
2303
+ if (global.gc && chunkEnd < totalFrames) {
2304
+ global.gc();
2292
2305
  }
2293
2306
  }
2294
2307
  ffmpeg.stdin.end();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shotstack/shotstack-canvas",
3
- "version": "1.5.7",
3
+ "version": "1.5.8",
4
4
  "description": "Text layout & animation engine (HarfBuzz) for Node & Web - fully self-contained.",
5
5
  "type": "module",
6
6
  "main": "./dist/entry.node.cjs",