mirror of
https://github.com/wukko/cobalt.git
synced 2025-05-29 21:10:14 +02:00
web/queue: add remuxing progress & general improvements
and a bunch of other stuff: - size and percentage in queue - indeterminate progress bar - if libav wasm freezes, the worker kill itself - cleaner states - cleaner props
This commit is contained in:
parent
c4c47bdc27
commit
44a99bdb3a
@ -16,7 +16,6 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const dragOverHandler = (ev: DragEvent) => {
|
const dragOverHandler = (ev: DragEvent) => {
|
||||||
console.log("dragged over omg")
|
|
||||||
draggedOver = true;
|
draggedOver = true;
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
};
|
};
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
$: queueLength = Object.keys($queue).length;
|
$: queueLength = Object.keys($queue).length;
|
||||||
$: completedQueueItems = queueItems.filter(([id, item]) => {
|
$: completedQueueItems = queueItems.filter(([id, item]) => {
|
||||||
return item.state === "done"
|
return item.state === "done";
|
||||||
}).length;
|
}).length;
|
||||||
|
|
||||||
// TODO: toggle this only when progress is unknown
|
// TODO: toggle this only when progress is unknown
|
||||||
@ -42,7 +42,11 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div id="processing-queue" class:expanded>
|
<div id="processing-queue" class:expanded>
|
||||||
<ProcessingStatus progress={(completedQueueItems / queueLength) * 100} {indeterminate} expandAction={popover?.showPopover} />
|
<ProcessingStatus
|
||||||
|
progress={(completedQueueItems / queueLength) * 100}
|
||||||
|
{indeterminate}
|
||||||
|
expandAction={popover?.showPopover}
|
||||||
|
/>
|
||||||
|
|
||||||
<PopoverContainer
|
<PopoverContainer
|
||||||
bind:this={popover}
|
bind:this={popover}
|
||||||
@ -71,10 +75,10 @@
|
|||||||
{#each queueItems as [id, item]}
|
{#each queueItems as [id, item]}
|
||||||
<ProcessingQueueItem
|
<ProcessingQueueItem
|
||||||
{id}
|
{id}
|
||||||
mediaType={item.mediaType}
|
info={item}
|
||||||
filename={item.filename}
|
runningWorker={
|
||||||
state={item.state}
|
item.state === "running" ? $currentTasks[item.runningWorker] : undefined
|
||||||
resultFile={item.state === "done" ? item.resultFile : undefined}
|
}
|
||||||
/>
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
{#if queueLength === 0}
|
{#if queueLength === 0}
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { queue, removeItem } from "$lib/state/queen-bee/queue";
|
import { downloadFile } from "$lib/download";
|
||||||
|
import { removeItem } from "$lib/state/queen-bee/queue";
|
||||||
|
|
||||||
|
import type { CobaltQueueItem } from "$lib/types/queue";
|
||||||
|
import type { CobaltCurrentTaskItem } from "$lib/types/queen-bee";
|
||||||
|
|
||||||
|
import Skeleton from "$components/misc/Skeleton.svelte";
|
||||||
|
|
||||||
import IconX from "@tabler/icons-svelte/IconX.svelte";
|
import IconX from "@tabler/icons-svelte/IconX.svelte";
|
||||||
import IconDownload from "@tabler/icons-svelte/IconDownload.svelte";
|
import IconDownload from "@tabler/icons-svelte/IconDownload.svelte";
|
||||||
@ -7,9 +13,6 @@
|
|||||||
import IconMovie from "@tabler/icons-svelte/IconMovie.svelte";
|
import IconMovie from "@tabler/icons-svelte/IconMovie.svelte";
|
||||||
import IconMusic from "@tabler/icons-svelte/IconMusic.svelte";
|
import IconMusic from "@tabler/icons-svelte/IconMusic.svelte";
|
||||||
import IconPhoto from "@tabler/icons-svelte/IconPhoto.svelte";
|
import IconPhoto from "@tabler/icons-svelte/IconPhoto.svelte";
|
||||||
import { downloadFile } from "$lib/download";
|
|
||||||
import type { CobaltQueueItemState } from "$lib/types/queue";
|
|
||||||
import type { CobaltPipelineResultFileType } from "$lib/types/workers";
|
|
||||||
|
|
||||||
const itemIcons = {
|
const itemIcons = {
|
||||||
video: IconMovie,
|
video: IconMovie,
|
||||||
@ -18,13 +21,12 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
export let id: string;
|
export let id: string;
|
||||||
export let mediaType: CobaltPipelineResultFileType;
|
export let info: CobaltQueueItem;
|
||||||
export let filename: string;
|
export let runningWorker: CobaltCurrentTaskItem | undefined;
|
||||||
export let state: CobaltQueueItemState;
|
|
||||||
export let resultFile: File | undefined;
|
|
||||||
|
|
||||||
// TODO: use a real value
|
$: state = info.state;
|
||||||
const progress = 0;
|
|
||||||
|
$: progress = runningWorker?.progress;
|
||||||
|
|
||||||
const download = (file: File) =>
|
const download = (file: File) =>
|
||||||
downloadFile({
|
downloadFile({
|
||||||
@ -36,27 +38,47 @@
|
|||||||
<div class="processing-info">
|
<div class="processing-info">
|
||||||
<div class="file-title">
|
<div class="file-title">
|
||||||
<div class="processing-type">
|
<div class="processing-type">
|
||||||
<svelte:component this={itemIcons[mediaType]} />
|
<svelte:component this={itemIcons[info.mediaType]} />
|
||||||
</div>
|
</div>
|
||||||
<span>
|
<span>
|
||||||
{filename}
|
{info.filename}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{#if state === "running"}
|
{#if state === "running"}
|
||||||
<div class="file-progress">
|
<div class="file-progress">
|
||||||
<div
|
{#if progress?.percentage}
|
||||||
class="progress"
|
<div
|
||||||
style="width: {Math.min(100, progress)}%"
|
class="progress"
|
||||||
></div>
|
style="width: {Math.min(100, progress?.percentage || 0)}%"
|
||||||
|
></div>
|
||||||
|
{:else}
|
||||||
|
<Skeleton height="6px" width="100%" class="elevated indeterminate-progress" />
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="file-status">{id}: {state}</div>
|
<div class="file-status">
|
||||||
|
{#if info.state === "done"}
|
||||||
|
done: {info.resultFile?.size} bytes
|
||||||
|
{:else if info.state === "running"}
|
||||||
|
{#if progress && progress.percentage}
|
||||||
|
processing: {Math.ceil(progress.percentage)}%, {progress.size} bytes
|
||||||
|
{:else if progress && progress.size}
|
||||||
|
processing: {progress.size}
|
||||||
|
{:else}
|
||||||
|
processing...
|
||||||
|
{/if}
|
||||||
|
{:else if info.state === "error"}
|
||||||
|
error: {info.errorCode}
|
||||||
|
{:else}
|
||||||
|
queued
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="file-actions">
|
<div class="file-actions">
|
||||||
{#if state === "done" && resultFile}
|
{#if info.state === "done" && info.resultFile}
|
||||||
<button
|
<button
|
||||||
class="action-button"
|
class="action-button"
|
||||||
on:click={() => download(resultFile)}
|
on:click={() => download(info.resultFile)}
|
||||||
>
|
>
|
||||||
<IconDownload />
|
<IconDownload />
|
||||||
</button>
|
</button>
|
||||||
@ -112,6 +134,11 @@
|
|||||||
.file-progress .progress {
|
.file-progress .progress {
|
||||||
height: 6px;
|
height: 6px;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
|
transition: width 0.1s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-progress :global(.indeterminate-progress) {
|
||||||
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.file-progress .progress {
|
.file-progress .progress {
|
||||||
|
@ -38,7 +38,7 @@ export default class LibAVWrapper {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await libav.ffprobe([
|
await libav.ffprobe([
|
||||||
//'-v', 'quiet',
|
'-v', 'quiet',
|
||||||
'-print_format', 'json',
|
'-print_format', 'json',
|
||||||
'-show_format',
|
'-show_format',
|
||||||
'-show_streams',
|
'-show_streams',
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import RemuxWorker from "$lib/workers/remux?worker";
|
import RemuxWorker from "$lib/workers/remux?worker";
|
||||||
//import RemoveBgWorker from "$lib/workers/removebg?worker";
|
|
||||||
|
|
||||||
import type { CobaltPipelineItem } from "$lib/types/workers";
|
import type { CobaltPipelineItem } from "$lib/types/workers";
|
||||||
import { itemDone, itemError } from "$lib/state/queen-bee/queue";
|
import { itemDone, itemError } from "$lib/state/queen-bee/queue";
|
||||||
|
import { updateWorkerProgress } from "$lib/state/queen-bee/current-tasks";
|
||||||
|
|
||||||
const workerError = (parentId: string, workerId: string, worker: Worker, error: string) => {
|
const workerError = (parentId: string, workerId: string, worker: Worker, error: string) => {
|
||||||
itemError(parentId, workerId, error);
|
itemError(parentId, workerId, error);
|
||||||
@ -26,13 +26,43 @@ export const runRemuxWorker = async (workerId: string, parentId: string, file: F
|
|||||||
workerError(parentId, workerId, worker, "internal error");
|
workerError(parentId, workerId, worker, "internal error");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// sometimes chrome refuses to start libav wasm,
|
||||||
|
// so we check the health and kill self if it doesn't spawn
|
||||||
|
|
||||||
|
let bumpAttempts = 0;
|
||||||
|
const startCheck = setInterval(() => {
|
||||||
|
bumpAttempts++;
|
||||||
|
|
||||||
|
if (bumpAttempts === 8) {
|
||||||
|
worker.terminate();
|
||||||
|
console.error("worker didn't start after 4 seconds, so it was killed");
|
||||||
|
|
||||||
|
// TODO: proper error code
|
||||||
|
return workerError(parentId, workerId, worker, "worker didn't start");
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
let totalDuration: number | null = null;
|
||||||
|
|
||||||
worker.onmessage = (event) => {
|
worker.onmessage = (event) => {
|
||||||
const eventData = event.data.cobaltRemuxWorker;
|
const eventData = event.data.cobaltRemuxWorker;
|
||||||
if (!eventData) return;
|
if (!eventData) return;
|
||||||
|
|
||||||
console.log(eventData);
|
// temporary debug logging
|
||||||
|
console.log(JSON.stringify(eventData, null, 2));
|
||||||
|
|
||||||
// TODO: calculate & use progress again
|
clearInterval(startCheck);
|
||||||
|
|
||||||
|
if (eventData.progress) {
|
||||||
|
if (eventData.progress.duration) {
|
||||||
|
totalDuration = eventData.progress.duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateWorkerProgress(workerId, {
|
||||||
|
percentage: totalDuration ? (eventData.progress.durationProcessed / totalDuration) * 100 : 0,
|
||||||
|
size: eventData.progress.size,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (eventData.render) {
|
if (eventData.render) {
|
||||||
return workerSuccess(
|
return workerSuccess(
|
||||||
|
@ -23,16 +23,16 @@ export const checkTasks = () => {
|
|||||||
// one parent & pipeline
|
// one parent & pipeline
|
||||||
const pipelineItem = task.pipeline[i];
|
const pipelineItem = task.pipeline[i];
|
||||||
|
|
||||||
startWorker(pipelineItem);
|
addWorkerToQueue(pipelineItem.workerId, {
|
||||||
|
|
||||||
addWorkerToQueue({
|
|
||||||
id: pipelineItem.workerId,
|
|
||||||
parentId: task.id,
|
parentId: task.id,
|
||||||
step: i + 1,
|
|
||||||
totalSteps: task.pipeline.length,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
itemRunning(task.id, i);
|
itemRunning(
|
||||||
|
task.id,
|
||||||
|
pipelineItem.workerId
|
||||||
|
);
|
||||||
|
|
||||||
|
startWorker(pipelineItem);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -10,9 +10,9 @@ const currentTasks = readable<CobaltCurrentTasks>(
|
|||||||
(_, _update) => { update = _update }
|
(_, _update) => { update = _update }
|
||||||
);
|
);
|
||||||
|
|
||||||
export function addWorkerToQueue(item: CobaltCurrentTaskItem) {
|
export function addWorkerToQueue(workerId: string, item: CobaltCurrentTaskItem) {
|
||||||
update(tasks => {
|
update(tasks => {
|
||||||
tasks[item.id] = item;
|
tasks[workerId] = item;
|
||||||
return tasks;
|
return tasks;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -24,10 +24,10 @@ export function removeWorkerFromQueue(id: string) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateWorkerProgress(id: string, progress: CobaltWorkerProgress) {
|
export function updateWorkerProgress(workerId: string, progress: CobaltWorkerProgress) {
|
||||||
update(tasks => {
|
update(allTasks => {
|
||||||
tasks[id].progress = progress;
|
allTasks[workerId].progress = progress;
|
||||||
return tasks;
|
return allTasks;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,13 +51,13 @@ export function itemDone(id: string, workerId: string, file: File) {
|
|||||||
checkTasks();
|
checkTasks();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function itemRunning(id: string, step: number) {
|
export function itemRunning(id: string, workerId: string) {
|
||||||
update(queueData => {
|
update(queueData => {
|
||||||
if (queueData[id]) {
|
if (queueData[id]) {
|
||||||
queueData[id] = {
|
queueData[id] = {
|
||||||
...queueData[id],
|
...queueData[id],
|
||||||
state: "running",
|
state: "running",
|
||||||
currentStep: step,
|
runningWorker: workerId,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return queueData;
|
return queueData;
|
||||||
@ -68,6 +68,10 @@ export function itemRunning(id: string, step: number) {
|
|||||||
|
|
||||||
export function removeItem(id: string) {
|
export function removeItem(id: string) {
|
||||||
update(queueData => {
|
update(queueData => {
|
||||||
|
for (const worker in queueData[id].pipeline) {
|
||||||
|
removeWorkerFromQueue(queueData[id].pipeline[worker].workerId);
|
||||||
|
}
|
||||||
|
|
||||||
delete queueData[id];
|
delete queueData[id];
|
||||||
return queueData;
|
return queueData;
|
||||||
});
|
});
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
import type { CobaltWorkerProgress } from "$lib/types/workers";
|
import type { CobaltWorkerProgress } from "$lib/types/workers";
|
||||||
|
|
||||||
export type CobaltCurrentTaskItem = {
|
export type CobaltCurrentTaskItem = {
|
||||||
id: string,
|
parentId: string,
|
||||||
parentId: string, // parent id is queue id to which this pipeline worker belongs to
|
|
||||||
step: number,
|
|
||||||
totalSteps: number,
|
|
||||||
progress?: CobaltWorkerProgress,
|
progress?: CobaltWorkerProgress,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ export type CobaltQueueItemWaiting = CobaltQueueBaseItem & {
|
|||||||
|
|
||||||
export type CobaltQueueItemRunning = CobaltQueueBaseItem & {
|
export type CobaltQueueItemRunning = CobaltQueueBaseItem & {
|
||||||
state: "running",
|
state: "running",
|
||||||
currentStep: number,
|
runningWorker: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CobaltQueueItemDone = CobaltQueueBaseItem & {
|
export type CobaltQueueItemDone = CobaltQueueBaseItem & {
|
||||||
|
@ -4,9 +4,9 @@ export type CobaltWorkerType = "remux" | "removebg";
|
|||||||
export type CobaltPipelineResultFileType = typeof resultFileTypes[number];
|
export type CobaltPipelineResultFileType = typeof resultFileTypes[number];
|
||||||
|
|
||||||
export type CobaltWorkerProgress = {
|
export type CobaltWorkerProgress = {
|
||||||
indeterminate: boolean,
|
percentage?: number,
|
||||||
speed?: number,
|
speed?: number,
|
||||||
percentage: number,
|
size: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CobaltWorkerArgs = {
|
export type CobaltWorkerArgs = {
|
||||||
|
@ -15,6 +15,9 @@ const ff = new LibAVWrapper((progress) => {
|
|||||||
progress: {
|
progress: {
|
||||||
durationProcessed: progress.out_time_sec,
|
durationProcessed: progress.out_time_sec,
|
||||||
speed: progress.speed,
|
speed: progress.speed,
|
||||||
|
size: progress.total_size,
|
||||||
|
currentFrame: progress.frame,
|
||||||
|
fps: progress.fps,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -45,7 +48,7 @@ const remux = async (file: File) => {
|
|||||||
|
|
||||||
self.postMessage({
|
self.postMessage({
|
||||||
cobaltRemuxWorker: {
|
cobaltRemuxWorker: {
|
||||||
progressInfo: {
|
progress: {
|
||||||
duration: Number(file_info.format.duration),
|
duration: Number(file_info.format.duration),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user