Skip to content

Commit 1590490

Browse files
committed
web/queue: add a remux worker to saving pipeline, use pipelineResults
1 parent f2325bd commit 1590490

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

web/src/lib/queen-bee/queue.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import mime from "mime";
2+
13
import { addItem } from "$lib/state/queen-bee/queue";
24
import type { CobaltPipelineItem } from "$lib/types/workers";
35
import type { CobaltLocalProcessingResponse } from "$lib/types/api";
@@ -49,7 +51,10 @@ export const createSavePipeline = (info: CobaltLocalProcessingResponse) => {
4951
const parentId = crypto.randomUUID();
5052
const pipeline: CobaltPipelineItem[] = [];
5153

52-
for (const tunnel of info.tunnel) {
54+
// reverse is needed for audio (second item) to be downloaded first
55+
const tunnels = info.tunnel.reverse();
56+
57+
for (const tunnel of tunnels) {
5358
pipeline.push({
5459
worker: "fetch",
5560
workerId: crypto.randomUUID(),
@@ -60,6 +65,24 @@ export const createSavePipeline = (info: CobaltLocalProcessingResponse) => {
6065
})
6166
}
6267

68+
pipeline.push({
69+
worker: "remux",
70+
workerId: crypto.randomUUID(),
71+
parentId,
72+
workerArgs: {
73+
ffargs: [
74+
"-c:v", "copy",
75+
"-c:a", "copy"
76+
],
77+
output: {
78+
// TODO: return mime type from api to avoid dragging a big ass package into web build
79+
type: mime.getType(info.filename) || undefined,
80+
extension: info.filename.split(".").pop(),
81+
},
82+
filename: info.filename,
83+
},
84+
})
85+
6386
addItem({
6487
id: parentId,
6588
state: "waiting",

web/src/lib/queen-bee/run-worker.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import RemuxWorker from "$lib/workers/remux?worker";
22
import FetchWorker from "$lib/workers/fetch?worker";
33

4+
import { get } from "svelte/store";
45
import { updateWorkerProgress } from "$lib/state/queen-bee/current-tasks";
56
import { pipelineTaskDone, itemError, queue } from "$lib/state/queen-bee/queue";
67

@@ -151,6 +152,13 @@ export const startWorker = async ({ worker, workerId, parentId, workerArgs }: Co
151152
files = workerArgs.files;
152153
}
153154

155+
if (files?.length === 0) {
156+
const parent = get(queue)[parentId];
157+
if (parent.state === "running" && parent.pipelineResults) {
158+
files = parent.pipelineResults;
159+
}
160+
}
161+
154162
if (files.length > 0 && workerArgs.ffargs && workerArgs.output && workerArgs.filename) {
155163
await runRemuxWorker(
156164
workerId,

web/src/lib/workers/remux.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const remux = async (files: File[], args: string[], output: FileInfo, filename:
3131
await ff.init();
3232

3333
try {
34+
// probing just the first file in files array (usually audio) for duration progress
3435
const file_info = await ff.probe(files[0]).catch((e) => {
3536
if (e?.message?.toLowerCase().includes("out of memory")) {
3637
console.error("uh oh! out of memory");

0 commit comments

Comments
 (0)