fix: enhance copyToWorkDir to log progress and improve video bitrate estimation in transcoding
Build / Lint & Test (push) Successful in 16s

This commit is contained in:
PickleRick committed 2026-09-19 23:10:20 +02:00
1 parent 0c8b713325
commit 36184fbf32
3 files changed
+68 -7

No files matched your search

@@ -82,9 +82,13 @@ const plugin = async (args) => {
}
// ── Copy using streams (no RAM spike for large files) ────────────────────
jobLog(`[copyToWorkDir] Copying to: ${localCopy}\n`);
const sourceSize = fs.statSync(inputFile).size;
const sourceSizeMb = (sourceSize / 1024 / 1024).toFixed(1);
jobLog(`[copyToWorkDir] Copying ${sourceSizeMb} MB to: ${localCopy}\n`);
const startMs = Date.now();
let copiedBytes = 0;
let nextProgressPercent = 10;
await new Promise((resolve, reject) => {
const rd = fs.createReadStream(inputFile);
@@ -93,6 +97,19 @@ const plugin = async (args) => {
rd.on('error', reject);
wr.on('error', reject);
wr.on('finish', resolve);
rd.on('data', (chunk) => {
copiedBytes += chunk.length;
if (sourceSize <= 0) return;
const percent = Math.floor((copiedBytes / sourceSize) * 100);
if (percent < nextProgressPercent) return;
const elapsedSeconds = Math.max((Date.now() - startMs) / 1000, 0.1);
const copiedMb = (copiedBytes / 1024 / 1024).toFixed(1);
const speedMbPerSecond = (copiedBytes / 1024 / 1024 / elapsedSeconds).toFixed(1);
jobLog(`[copyToWorkDir] Progress: ${Math.min(percent, 100)}% (${copiedMb}/${sourceSizeMb} MB, ${speedMbPerSecond} MB/s)\n`);
nextProgressPercent = (Math.floor(percent / 10) + 1) * 10;
});
rd.pipe(wr);
});