mirror of
https://github.com/wukko/cobalt.git
synced 2025-05-29 04:50:13 +02:00
web: simplify CobaltFileReference type
This commit is contained in:
parent
95ab81eb10
commit
1ef8391639
@ -90,7 +90,7 @@
|
|||||||
return $t("queue.state.starting");
|
return $t("queue.state.starting");
|
||||||
|
|
||||||
case "done":
|
case "done":
|
||||||
return formatFileSize(info.resultFile?.file?.size);
|
return formatFileSize(info.resultFile?.size);
|
||||||
|
|
||||||
case "error":
|
case "error":
|
||||||
return !retrying ? info.errorCode : $t("queue.state.retrying");
|
return !retrying ? info.errorCode : $t("queue.state.retrying");
|
||||||
@ -162,7 +162,7 @@
|
|||||||
{#if info.state === "done" && info.resultFile}
|
{#if info.state === "done" && info.resultFile}
|
||||||
<button
|
<button
|
||||||
class="button action-button"
|
class="button action-button"
|
||||||
on:click={() => download(info.resultFile.file)}
|
on:click={() => download(info.resultFile)}
|
||||||
>
|
>
|
||||||
<IconDownload />
|
<IconDownload />
|
||||||
</button>
|
</button>
|
||||||
|
@ -86,7 +86,7 @@ export default class LibAVWrapper {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
for (let i = 0; i < files.length; i++) {
|
for (let i = 0; i < files.length; i++) {
|
||||||
const file = files[i].file;
|
const file = files[i];
|
||||||
|
|
||||||
await libav.mkreadaheadfile(`input${i}`, file);
|
await libav.mkreadaheadfile(`input${i}`, file);
|
||||||
ffInputs.push('-i', `input${i}`);
|
ffInputs.push('-i', `input${i}`);
|
||||||
@ -95,7 +95,7 @@ export default class LibAVWrapper {
|
|||||||
await libav.mkwriterdev(outputName);
|
await libav.mkwriterdev(outputName);
|
||||||
await libav.mkwriterdev('progress.txt');
|
await libav.mkwriterdev('progress.txt');
|
||||||
|
|
||||||
const totalInputSize = files.reduce((a, b) => a + b.file.size, 0);
|
const totalInputSize = files.reduce((a, b) => a + b.size, 0);
|
||||||
const storage = await Storage.init(totalInputSize);
|
const storage = await Storage.init(totalInputSize);
|
||||||
|
|
||||||
libav.onwrite = async (name, pos, data) => {
|
libav.onwrite = async (name, pos, data) => {
|
||||||
@ -120,14 +120,15 @@ export default class LibAVWrapper {
|
|||||||
outputName
|
outputName
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const file = await storage.res();
|
const file = new File(
|
||||||
|
[ await storage.res() ],
|
||||||
|
outputName,
|
||||||
|
{ type: output.type }
|
||||||
|
);
|
||||||
|
|
||||||
if (file.size === 0) return;
|
if (file.size === 0) return;
|
||||||
|
|
||||||
return {
|
return file;
|
||||||
file,
|
|
||||||
type: output.type,
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
await libav.unlink(outputName);
|
await libav.unlink(outputName);
|
||||||
|
@ -4,17 +4,16 @@ import { schedule } from "$lib/task-manager/scheduler";
|
|||||||
import { clearFileStorage, removeFromFileStorage } from "$lib/storage/opfs";
|
import { clearFileStorage, removeFromFileStorage } from "$lib/storage/opfs";
|
||||||
import { clearCurrentTasks, removeWorkerFromQueue } from "$lib/state/task-manager/current-tasks";
|
import { clearCurrentTasks, removeWorkerFromQueue } from "$lib/state/task-manager/current-tasks";
|
||||||
|
|
||||||
import type { CobaltFileReference } from "$lib/types/storage";
|
|
||||||
import type { CobaltQueue, CobaltQueueItem, CobaltQueueItemRunning } from "$lib/types/queue";
|
import type { CobaltQueue, CobaltQueueItem, CobaltQueueItemRunning } from "$lib/types/queue";
|
||||||
|
|
||||||
const clearPipelineCache = (queueItem: CobaltQueueItem) => {
|
const clearPipelineCache = (queueItem: CobaltQueueItem) => {
|
||||||
if (queueItem.state === "running") {
|
if (queueItem.state === "running") {
|
||||||
let item: CobaltFileReference | undefined;
|
let item: File | undefined;
|
||||||
while ((item = queueItem.pipelineResults.pop())) {
|
while ((item = queueItem.pipelineResults.pop())) {
|
||||||
removeFromFileStorage(item.file.name);
|
removeFromFileStorage(item.name);
|
||||||
}
|
}
|
||||||
} else if (queueItem.state === "done") {
|
} else if (queueItem.state === "done") {
|
||||||
removeFromFileStorage(queueItem.resultFile.file.name);
|
removeFromFileStorage(queueItem.resultFile.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return queueItem;
|
return queueItem;
|
||||||
@ -54,7 +53,7 @@ export function itemError(id: string, workerId: string, error: string) {
|
|||||||
schedule();
|
schedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function itemDone(id: string, file: CobaltFileReference) {
|
export function itemDone(id: string, file: File) {
|
||||||
update(queueData => {
|
update(queueData => {
|
||||||
if (queueData[id]) {
|
if (queueData[id]) {
|
||||||
queueData[id] = clearPipelineCache(queueData[id]);
|
queueData[id] = clearPipelineCache(queueData[id]);
|
||||||
@ -71,7 +70,7 @@ export function itemDone(id: string, file: CobaltFileReference) {
|
|||||||
schedule();
|
schedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function pipelineTaskDone(id: string, workerId: string, file: CobaltFileReference) {
|
export function pipelineTaskDone(id: string, workerId: string, file: File) {
|
||||||
update(queueData => {
|
update(queueData => {
|
||||||
const item = queueData[id];
|
const item = queueData[id];
|
||||||
|
|
||||||
|
@ -24,10 +24,7 @@ export const createRemuxPipeline = (file: File) => {
|
|||||||
workerId: crypto.randomUUID(),
|
workerId: crypto.randomUUID(),
|
||||||
parentId,
|
parentId,
|
||||||
workerArgs: {
|
workerArgs: {
|
||||||
files: [{
|
files: [file],
|
||||||
file,
|
|
||||||
type: file.type,
|
|
||||||
}],
|
|
||||||
ffargs: [
|
ffargs: [
|
||||||
"-c", "copy",
|
"-c", "copy",
|
||||||
"-map", "0"
|
"-map", "0"
|
||||||
|
@ -5,7 +5,6 @@ import { runFFmpegWorker } from "$lib/task-manager/runners/ffmpeg";
|
|||||||
import { runFetchWorker } from "$lib/task-manager/runners/fetch";
|
import { runFetchWorker } from "$lib/task-manager/runners/fetch";
|
||||||
|
|
||||||
import type { CobaltPipelineItem } from "$lib/types/workers";
|
import type { CobaltPipelineItem } from "$lib/types/workers";
|
||||||
import type { CobaltFileReference } from "$lib/types/storage";
|
|
||||||
|
|
||||||
export const killWorker = (worker: Worker, unsubscribe: () => void, interval?: NodeJS.Timeout) => {
|
export const killWorker = (worker: Worker, unsubscribe: () => void, interval?: NodeJS.Timeout) => {
|
||||||
unsubscribe();
|
unsubscribe();
|
||||||
@ -14,7 +13,7 @@ export const killWorker = (worker: Worker, unsubscribe: () => void, interval?: N
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const startWorker = async ({ worker, workerId, parentId, workerArgs }: CobaltPipelineItem) => {
|
export const startWorker = async ({ worker, workerId, parentId, workerArgs }: CobaltPipelineItem) => {
|
||||||
let files: CobaltFileReference[] = [];
|
let files: File[] = [];
|
||||||
|
|
||||||
switch (worker) {
|
switch (worker) {
|
||||||
case "remux":
|
case "remux":
|
||||||
|
@ -6,14 +6,13 @@ import { pipelineTaskDone, itemError, queue } from "$lib/state/task-manager/queu
|
|||||||
|
|
||||||
import type { FileInfo } from "$lib/types/libav";
|
import type { FileInfo } from "$lib/types/libav";
|
||||||
import type { CobaltQueue } from "$lib/types/queue";
|
import type { CobaltQueue } from "$lib/types/queue";
|
||||||
import type { CobaltFileReference } from "$lib/types/storage";
|
|
||||||
|
|
||||||
let startAttempts = 0;
|
let startAttempts = 0;
|
||||||
|
|
||||||
export const runFFmpegWorker = async (
|
export const runFFmpegWorker = async (
|
||||||
workerId: string,
|
workerId: string,
|
||||||
parentId: string,
|
parentId: string,
|
||||||
files: CobaltFileReference[],
|
files: File[],
|
||||||
args: string[],
|
args: string[],
|
||||||
output: FileInfo,
|
output: FileInfo,
|
||||||
variant: 'remux' | 'encode',
|
variant: 'remux' | 'encode',
|
||||||
|
@ -76,7 +76,9 @@ const fetchFile = async (url: string) => {
|
|||||||
return error("tunnel is broken");
|
return error("tunnel is broken");
|
||||||
}
|
}
|
||||||
|
|
||||||
const file = await storage.res();
|
const file = new File(
|
||||||
|
[ await storage.res() ], '', { type: contentType }
|
||||||
|
);
|
||||||
|
|
||||||
if (contentLength && Number(contentLength) !== file.size) {
|
if (contentLength && Number(contentLength) !== file.size) {
|
||||||
return error("file was not downloaded fully");
|
return error("file was not downloaded fully");
|
||||||
@ -84,10 +86,7 @@ const fetchFile = async (url: string) => {
|
|||||||
|
|
||||||
self.postMessage({
|
self.postMessage({
|
||||||
cobaltFetchWorker: {
|
cobaltFetchWorker: {
|
||||||
result: {
|
result: file
|
||||||
file,
|
|
||||||
type: contentType,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import LibAVWrapper from "$lib/libav";
|
import LibAVWrapper from "$lib/libav";
|
||||||
|
|
||||||
import type { FileInfo } from "$lib/types/libav";
|
import type { FileInfo } from "$lib/types/libav";
|
||||||
import type { CobaltFileReference } from "$lib/types/storage";
|
|
||||||
|
|
||||||
const error = (code: string) => {
|
const error = (code: string) => {
|
||||||
self.postMessage({
|
self.postMessage({
|
||||||
@ -11,7 +10,7 @@ const error = (code: string) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const ffmpeg = async (variant: string, files: CobaltFileReference[], args: string[], output: FileInfo) => {
|
const ffmpeg = async (variant: string, files: File[], args: string[], output: FileInfo) => {
|
||||||
if (!(files && output && args)) return;
|
if (!(files && output && args)) return;
|
||||||
|
|
||||||
const ff = new LibAVWrapper((progress) => {
|
const ff = new LibAVWrapper((progress) => {
|
||||||
@ -32,7 +31,7 @@ const ffmpeg = async (variant: string, files: CobaltFileReference[], args: strin
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// probing just the first file in files array (usually audio) for duration progress
|
// probing just the first file in files array (usually audio) for duration progress
|
||||||
const probeFile = files[0]?.file;
|
const probeFile = files[0];
|
||||||
if (!probeFile) return error("couldn't probe one of files");
|
if (!probeFile) return error("couldn't probe one of files");
|
||||||
|
|
||||||
const file_info = await ff.probe(probeFile).catch((e) => {
|
const file_info = await ff.probe(probeFile).catch((e) => {
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
import type { CobaltFileReference } from "$lib/types/storage";
|
|
||||||
|
|
||||||
export type FileInfo = {
|
export type FileInfo = {
|
||||||
type?: string,
|
type?: string,
|
||||||
format?: string,
|
format?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type RenderParams = {
|
export type RenderParams = {
|
||||||
files: CobaltFileReference[],
|
files: File[],
|
||||||
output: FileInfo,
|
output: FileInfo,
|
||||||
args: string[],
|
args: string[],
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import type { CobaltSaveRequestBody } from "$lib/types/api";
|
import type { CobaltSaveRequestBody } from "$lib/types/api";
|
||||||
import type { CobaltFileReference } from "$lib/types/storage";
|
|
||||||
import type { CobaltPipelineItem, CobaltPipelineResultFileType } from "$lib/types/workers";
|
import type { CobaltPipelineItem, CobaltPipelineResultFileType } from "$lib/types/workers";
|
||||||
|
|
||||||
export type CobaltQueueItemState = "waiting" | "running" | "done" | "error";
|
export type CobaltQueueItemState = "waiting" | "running" | "done" | "error";
|
||||||
@ -24,12 +23,12 @@ export type CobaltQueueItemRunning = CobaltQueueBaseItem & {
|
|||||||
state: "running",
|
state: "running",
|
||||||
runningWorker: string,
|
runningWorker: string,
|
||||||
completedWorkers: Set<string>,
|
completedWorkers: Set<string>,
|
||||||
pipelineResults: CobaltFileReference[],
|
pipelineResults: File[],
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CobaltQueueItemDone = CobaltQueueBaseItem & {
|
export type CobaltQueueItemDone = CobaltQueueBaseItem & {
|
||||||
state: "done",
|
state: "done",
|
||||||
resultFile: CobaltFileReference,
|
resultFile: File,
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CobaltQueueItemError = CobaltQueueBaseItem & {
|
export type CobaltQueueItemError = CobaltQueueBaseItem & {
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
export type CobaltFileReference = {
|
|
||||||
file: File,
|
|
||||||
type: string,
|
|
||||||
}
|
|
@ -1,5 +1,4 @@
|
|||||||
import type { FileInfo } from "$lib/types/libav";
|
import type { FileInfo } from "$lib/types/libav";
|
||||||
import type { CobaltFileReference } from "$lib/types/storage";
|
|
||||||
|
|
||||||
export const resultFileTypes = ["video", "audio", "image"] as const;
|
export const resultFileTypes = ["video", "audio", "image"] as const;
|
||||||
|
|
||||||
@ -12,7 +11,7 @@ export type CobaltWorkerProgress = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CobaltFFmpegWorkerArgs = {
|
type CobaltFFmpegWorkerArgs = {
|
||||||
files: CobaltFileReference[],
|
files: File[],
|
||||||
ffargs: string[],
|
ffargs: string[],
|
||||||
output: FileInfo,
|
output: FileInfo,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user