web/workers/remux: accept several files, custom args and output

This commit is contained in:
wukko
2025-01-31 11:16:04 +06:00
parent 7caee22aee
commit f2325bdc24
4 changed files with 56 additions and 29 deletions

View File

@@ -22,6 +22,15 @@ export const createRemuxPipeline = (file: File) => {
parentId,
workerArgs: {
files: [file],
ffargs: [
"-c", "copy",
"-map", "0"
],
output: {
type: file.type,
extension: file.name.split(".").pop(),
},
filename: file.name,
},
}];

View File

@@ -4,6 +4,7 @@ import FetchWorker from "$lib/workers/fetch?worker";
import { updateWorkerProgress } from "$lib/state/queen-bee/current-tasks";
import { pipelineTaskDone, itemError, queue } from "$lib/state/queen-bee/queue";
import type { FileInfo } from "$lib/types/libav";
import type { CobaltQueue } from "$lib/types/queue";
import type { CobaltPipelineItem } from "$lib/types/workers";
@@ -13,7 +14,7 @@ const killWorker = (worker: Worker, unsubscribe: () => void, interval?: NodeJS.T
if (interval) clearInterval(interval);
}
export const runRemuxWorker = async (workerId: string, parentId: string, file: File) => {
export const runRemuxWorker = async (workerId: string, parentId: string, files: File[], args: string[], output: FileInfo, filename: string) => {
const worker = new RemuxWorker();
// sometimes chrome refuses to start libav wasm,
@@ -42,7 +43,10 @@ export const runRemuxWorker = async (workerId: string, parentId: string, file: F
worker.postMessage({
cobaltRemuxWorker: {
file
files,
args,
output,
filename,
}
});
@@ -139,12 +143,26 @@ export const runFetchWorker = async (workerId: string, parentId: string, url: st
}
export const startWorker = async ({ worker, workerId, parentId, workerArgs }: CobaltPipelineItem) => {
let files: File[] = [];
switch (worker) {
case "remux":
if (workerArgs?.files) {
await runRemuxWorker(workerId, parentId, workerArgs.files[0]);
files = workerArgs.files;
}
if (files.length > 0 && workerArgs.ffargs && workerArgs.output && workerArgs.filename) {
await runRemuxWorker(
workerId,
parentId,
files,
workerArgs.ffargs,
workerArgs.output,
workerArgs.filename
);
}
break;
case "fetch":
if (workerArgs?.url) {
await runFetchWorker(workerId, parentId, workerArgs.url)