@boruto_vk7/stickengine 4.2.1 → 4.2.3
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 +1 -1
- package/dist/cjs/StickEngine.js +23 -14
- package/dist/esm/StickEngine.js +23 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @boruto_vk7/stickengine
|
|
2
2
|
|
|
3
|
-
> **4.2.
|
|
3
|
+
> **4.2.3 — 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→10, `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
|
[](https://www.npmjs.com/package/@boruto_vk7/stickengine)
|
package/dist/cjs/StickEngine.js
CHANGED
|
@@ -761,7 +761,7 @@ class StickEngine extends node_events_1.EventEmitter {
|
|
|
761
761
|
async detectVideoCropByCropdetect(input, mediaInfo) {
|
|
762
762
|
try {
|
|
763
763
|
const args = ['-nostdin', '-hide_banner', '-i', input, '-an'];
|
|
764
|
-
const sample = mediaInfo.duration > 0 ? Math.min(mediaInfo.duration,
|
|
764
|
+
const sample = mediaInfo.duration > 0 ? Math.min(mediaInfo.duration, 2) : 0;
|
|
765
765
|
if (sample > 0)
|
|
766
766
|
args.push('-t', String(sample));
|
|
767
767
|
args.push('-vf', `cropdetect=limit=${this.crop.tolerance}:round=2:reset=0`, '-f', 'null', '-');
|
|
@@ -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
|
-
//
|
|
1281
|
-
//
|
|
1282
|
-
const
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
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', '-
|
|
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 =
|
|
1353
|
+
let t = this.startTime > 0 ? this.startTime : 0;
|
|
1347
1354
|
for (let i = 0; i < k; i++) {
|
|
1348
|
-
|
|
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) {
|
|
@@ -1419,12 +1428,12 @@ class StickEngine extends node_events_1.EventEmitter {
|
|
|
1419
1428
|
let quality = this.options.quality != null
|
|
1420
1429
|
? (0, util_js_1.clamp)(Number(this.options.quality) || 80, 1, 100)
|
|
1421
1430
|
: (isAnimated ? 75 : 90);
|
|
1422
|
-
let fps = (0, util_js_1.clamp)(Math.round(Number(this.options.fps ??
|
|
1431
|
+
let fps = (0, util_js_1.clamp)(Math.round(Number(this.options.fps ?? 10) || 10), 1, 60);
|
|
1423
1432
|
// orçamento de frames: clipe longo roda com fps menor p/ codificar
|
|
1424
|
-
// menos frames e caber no maxSize sem re-encode (~
|
|
1433
|
+
// menos frames e caber no maxSize sem re-encode (~100 frames no total)
|
|
1425
1434
|
const clipeDur = this.duracaoClipe(opts.mediaInfo);
|
|
1426
|
-
if (isAnimated && this.options.fps == null && clipeDur >
|
|
1427
|
-
fps = Math.max(8, Math.round(
|
|
1435
|
+
if (isAnimated && this.options.fps == null && clipeDur > 10)
|
|
1436
|
+
fps = Math.max(8, Math.round(100 / clipeDur));
|
|
1428
1437
|
const limit = isAnimated ? this.maxSize : this.maxSizeStatic;
|
|
1429
1438
|
try {
|
|
1430
1439
|
const paralelo = isAnimated && !watermarkPath
|
package/dist/esm/StickEngine.js
CHANGED
|
@@ -746,7 +746,7 @@ export class StickEngine extends EventEmitter {
|
|
|
746
746
|
async detectVideoCropByCropdetect(input, mediaInfo) {
|
|
747
747
|
try {
|
|
748
748
|
const args = ['-nostdin', '-hide_banner', '-i', input, '-an'];
|
|
749
|
-
const sample = mediaInfo.duration > 0 ? Math.min(mediaInfo.duration,
|
|
749
|
+
const sample = mediaInfo.duration > 0 ? Math.min(mediaInfo.duration, 2) : 0;
|
|
750
750
|
if (sample > 0)
|
|
751
751
|
args.push('-t', String(sample));
|
|
752
752
|
args.push('-vf', `cropdetect=limit=${this.crop.tolerance}:round=2:reset=0`, '-f', 'null', '-');
|
|
@@ -1262,12 +1262,19 @@ export class StickEngine extends EventEmitter {
|
|
|
1262
1262
|
k = Math.round(Number(opt) || 0);
|
|
1263
1263
|
}
|
|
1264
1264
|
else {
|
|
1265
|
-
//
|
|
1266
|
-
//
|
|
1267
|
-
const
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
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', '-
|
|
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 =
|
|
1338
|
+
let t = this.startTime > 0 ? this.startTime : 0;
|
|
1332
1339
|
for (let i = 0; i < k; i++) {
|
|
1333
|
-
|
|
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) {
|
|
@@ -1404,12 +1413,12 @@ export class StickEngine extends EventEmitter {
|
|
|
1404
1413
|
let quality = this.options.quality != null
|
|
1405
1414
|
? clamp(Number(this.options.quality) || 80, 1, 100)
|
|
1406
1415
|
: (isAnimated ? 75 : 90);
|
|
1407
|
-
let fps = clamp(Math.round(Number(this.options.fps ??
|
|
1416
|
+
let fps = clamp(Math.round(Number(this.options.fps ?? 10) || 10), 1, 60);
|
|
1408
1417
|
// orçamento de frames: clipe longo roda com fps menor p/ codificar
|
|
1409
|
-
// menos frames e caber no maxSize sem re-encode (~
|
|
1418
|
+
// menos frames e caber no maxSize sem re-encode (~100 frames no total)
|
|
1410
1419
|
const clipeDur = this.duracaoClipe(opts.mediaInfo);
|
|
1411
|
-
if (isAnimated && this.options.fps == null && clipeDur >
|
|
1412
|
-
fps = Math.max(8, Math.round(
|
|
1420
|
+
if (isAnimated && this.options.fps == null && clipeDur > 10)
|
|
1421
|
+
fps = Math.max(8, Math.round(100 / clipeDur));
|
|
1413
1422
|
const limit = isAnimated ? this.maxSize : this.maxSizeStatic;
|
|
1414
1423
|
try {
|
|
1415
1424
|
const paralelo = isAnimated && !watermarkPath
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@boruto_vk7/stickengine",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.3",
|
|
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",
|