@boruto_vk7/stickengine 4.2.1 → 4.2.2

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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @boruto_vk7/stickengine
2
2
 
3
- > **4.2.1 — TURBO**: WebP animado agora é codificado **em paralelo** (um processo ffmpeg por núcleo, até 4) e os pedaços são remontados byte a byte, sem recodificar a junção. Defaults de velocidade: `fps` 15→12, `quality` animado 80→75, `compressionLevel` 6→1 (6 multiplicava o tempo de encode), auto-shrink proporcional (≤3 tentativas) e ffmpeg do sistema preferido quando tem `libwebp`. Um clipe de 4s que levava ~20s numa VPS fraca agora sai em poucos segundos. Desative o paralelismo com `parallelChunks: 1`.
3
+ > **4.2.2 — TURBO**: WebP animado agora é codificado **em paralelo** (um processo ffmpeg por núcleo, até 4) e os pedaços são remontados byte a byte, sem recodificar a junção. Defaults de velocidade: `fps` 15→12, `quality` animado 80→75, `compressionLevel` 6→1 (6 multiplicava o tempo de encode), auto-shrink proporcional (≤3 tentativas) e ffmpeg do sistema preferido quando tem `libwebp`. Um clipe de 4s que levava ~20s numa VPS fraca agora sai em poucos segundos. Desative o paralelismo com `parallelChunks: 1`.
4
4
 
5
5
 
6
6
  [![npm](https://img.shields.io/npm/v/@boruto_vk7/stickengine)](https://www.npmjs.com/package/@boruto_vk7/stickengine)
@@ -1277,12 +1277,19 @@ class StickEngine extends node_events_1.EventEmitter {
1277
1277
  k = Math.round(Number(opt) || 0);
1278
1278
  }
1279
1279
  else {
1280
- // availableParallelism respeita a cota de CPU do container (VPS/Docker);
1281
- // cpus() vê os núcleos do host e superestima em planos pequenos
1282
- const cores = typeof node_os_1.default.availableParallelism === 'function'
1283
- ? node_os_1.default.availableParallelism()
1284
- : node_os_1.default.cpus().length;
1285
- k = Math.min(4, Math.max(1, Math.ceil(cores * 0.75)));
1280
+ // calibração por ambiente: Docker/VPS com cota de CPU (os.cpus() vê
1281
+ // os núcleos do host e superestima em planos com cota pequena)
1282
+ const env = parseInt(String(process.env.STICKENGINE_PARALLEL_CHUNKS || ''), 10);
1283
+ if (Number.isFinite(env) && env >= 1) {
1284
+ k = env;
1285
+ }
1286
+ else {
1287
+ // availableParallelism respeita a cota de CPU do container
1288
+ const cores = typeof node_os_1.default.availableParallelism === 'function'
1289
+ ? node_os_1.default.availableParallelism()
1290
+ : node_os_1.default.cpus().length;
1291
+ k = Math.min(4, Math.max(1, Math.ceil(cores * 0.75)));
1292
+ }
1286
1293
  }
1287
1294
  k = Math.max(1, Math.min(8, k));
1288
1295
  if (totalFrames < 24)
@@ -1302,7 +1309,7 @@ class StickEngine extends node_events_1.EventEmitter {
1302
1309
  opts.push('-i', input);
1303
1310
  const vf = this.buildAnimatedFilters(crop, String(this.options.fit || 'cover'), fps);
1304
1311
  opts.push('-vf', vf);
1305
- opts.push('-frames:v', String(frames), '-c:v', 'libwebp', '-preset', 'default', '-an', '-loop', '0', '-vsync', '0', '-lossless', '0', '-compression_level', String(this.compressionLevelFor(isAnimated)), '-q:v', String(q), '-quality', String(q), '-y', output);
1312
+ opts.push('-frames:v', String(frames), '-c:v', 'libwebp', '-preset', 'default', '-an', '-loop', '0', '-lossless', '0', '-compression_level', String(this.compressionLevelFor(isAnimated)), '-q:v', String(q), '-quality', String(q), '-y', output);
1306
1313
  node_child_process_1.execFile(ffmpegPath || 'ffmpeg', opts, { timeout: 120000, maxBuffer: 16 * 1024 * 1024 }, (err, _so, se) => {
1307
1314
  if (err) {
1308
1315
  const detalhe = se ? ' — ' + String(se).split('\n').filter(Boolean).slice(-2).join(' ') : '';
@@ -1343,9 +1350,10 @@ class StickEngine extends node_events_1.EventEmitter {
1343
1350
  contagens.push(base + (resto-- > 0 ? 1 : 0));
1344
1351
  const arquivos = [];
1345
1352
  const promessas = [];
1346
- let t = inicio;
1353
+ let t = this.startTime > 0 ? this.startTime : 0;
1347
1354
  for (let i = 0; i < k; i++) {
1348
- const arq = output + '.p' + i;
1355
+ // extensão .webp obrigatória: o muxer do ffmpeg é escolhido pela extensão
1356
+ const arq = output.replace(/\.webp$/i, '') + '.p' + i + '.webp';
1349
1357
  arquivos.push(arq);
1350
1358
  promessas.push(this.runEncodeChunk(input, arq, t, contagens[i], true, quality, fps, crop));
1351
1359
  t += contagens[i] / fps;
@@ -1363,6 +1371,7 @@ class StickEngine extends node_events_1.EventEmitter {
1363
1371
  catch { /* ignore */ }
1364
1372
  }
1365
1373
  }
1374
+ this.say('info', 'ENCODE', `#· webp animado em ${k} pedaços paralelos (${total} frames)`);
1366
1375
  return true;
1367
1376
  }
1368
1377
  catch (e) {
@@ -1262,12 +1262,19 @@ export class StickEngine extends EventEmitter {
1262
1262
  k = Math.round(Number(opt) || 0);
1263
1263
  }
1264
1264
  else {
1265
- // availableParallelism respeita a cota de CPU do container (VPS/Docker);
1266
- // cpus() vê os núcleos do host e superestima em planos pequenos
1267
- const cores = typeof os.availableParallelism === 'function'
1268
- ? os.availableParallelism()
1269
- : os.cpus().length;
1270
- k = Math.min(4, Math.max(1, Math.ceil(cores * 0.75)));
1265
+ // calibração por ambiente: Docker/VPS com cota de CPU (os.cpus() vê
1266
+ // os núcleos do host e superestima em planos com cota pequena)
1267
+ const env = parseInt(String(process.env.STICKENGINE_PARALLEL_CHUNKS || ''), 10);
1268
+ if (Number.isFinite(env) && env >= 1) {
1269
+ k = env;
1270
+ }
1271
+ else {
1272
+ // availableParallelism respeita a cota de CPU do container
1273
+ const cores = typeof os.availableParallelism === 'function'
1274
+ ? os.availableParallelism()
1275
+ : os.cpus().length;
1276
+ k = Math.min(4, Math.max(1, Math.ceil(cores * 0.75)));
1277
+ }
1271
1278
  }
1272
1279
  k = Math.max(1, Math.min(8, k));
1273
1280
  if (totalFrames < 24)
@@ -1287,7 +1294,7 @@ export class StickEngine extends EventEmitter {
1287
1294
  opts.push('-i', input);
1288
1295
  const vf = this.buildAnimatedFilters(crop, String(this.options.fit || 'cover'), fps);
1289
1296
  opts.push('-vf', vf);
1290
- opts.push('-frames:v', String(frames), '-c:v', 'libwebp', '-preset', 'default', '-an', '-loop', '0', '-vsync', '0', '-lossless', '0', '-compression_level', String(this.compressionLevelFor(isAnimated)), '-q:v', String(q), '-quality', String(q), '-y', output);
1297
+ opts.push('-frames:v', String(frames), '-c:v', 'libwebp', '-preset', 'default', '-an', '-loop', '0', '-lossless', '0', '-compression_level', String(this.compressionLevelFor(isAnimated)), '-q:v', String(q), '-quality', String(q), '-y', output);
1291
1298
  execFile(ffmpegPath || 'ffmpeg', opts, { timeout: 120000, maxBuffer: 16 * 1024 * 1024 }, (err, _so, se) => {
1292
1299
  if (err) {
1293
1300
  const detalhe = se ? ' — ' + String(se).split('\n').filter(Boolean).slice(-2).join(' ') : '';
@@ -1328,9 +1335,10 @@ export class StickEngine extends EventEmitter {
1328
1335
  contagens.push(base + (resto-- > 0 ? 1 : 0));
1329
1336
  const arquivos = [];
1330
1337
  const promessas = [];
1331
- let t = inicio;
1338
+ let t = this.startTime > 0 ? this.startTime : 0;
1332
1339
  for (let i = 0; i < k; i++) {
1333
- const arq = output + '.p' + i;
1340
+ // extensão .webp obrigatória: o muxer do ffmpeg é escolhido pela extensão
1341
+ const arq = output.replace(/\.webp$/i, '') + '.p' + i + '.webp';
1334
1342
  arquivos.push(arq);
1335
1343
  promessas.push(this.runEncodeChunk(input, arq, t, contagens[i], true, quality, fps, crop));
1336
1344
  t += contagens[i] / fps;
@@ -1348,6 +1356,7 @@ export class StickEngine extends EventEmitter {
1348
1356
  catch { /* ignore */ }
1349
1357
  }
1350
1358
  }
1359
+ this.say('info', 'ENCODE', `#· webp animado em ${k} pedaços paralelos (${total} frames)`);
1351
1360
  return true;
1352
1361
  }
1353
1362
  catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boruto_vk7/stickengine",
3
- "version": "4.2.1",
3
+ "version": "4.2.2",
4
4
  "description": "WhatsApp sticker engine - media preparation only: 512x512 static/animated WebP, parallel animated encoding, automatic black-border removal, full-bleed cover fit, audio sticker pair (WebP + OGG/Opus), bundled canvas and ffmpeg binaries, pack EXIF, chalk logging. No message sending, no Baileys coupling.",
5
5
  "author": "Borutovk7 - Lagos Solutions",
6
6
  "license": "MIT",