mirror of
https://github.com/imputnet/cobalt.git
synced 2025-07-08 06:18:28 +00:00
web/ffmpeg: define multithreading support outside of web worker context
Some checks are pending
Some checks are pending
there's no navigator.maxTouchPoints in web worker context, so previously there was no way to detect whether safari is running on ipad or not
This commit is contained in:
parent
b2c5c42ae3
commit
9cc551008d
@ -5,12 +5,6 @@ import EncodeLibAV from "@imput/libav.js-encode-cli";
|
||||
import type { FfprobeData } from "fluent-ffmpeg";
|
||||
import type { FFmpegProgressCallback, FFmpegProgressEvent, FFmpegProgressStatus, RenderParams } from "$lib/types/libav";
|
||||
|
||||
const ua = navigator.userAgent.toLowerCase();
|
||||
const iPhone = ua.includes("iphone os");
|
||||
const iPad = !iPhone && ua.includes("mac os") && navigator.maxTouchPoints > 0;
|
||||
const iOS = iPhone || iPad;
|
||||
const modernIOS = iOS && Number(ua.match(/version\/(\d+)/)?.[1]) >= 18;
|
||||
|
||||
export default class LibAVWrapper {
|
||||
libav: Promise<LibAVInstance> | null;
|
||||
concurrency: number;
|
||||
@ -38,7 +32,6 @@ export default class LibAVWrapper {
|
||||
this.libav = constructor({
|
||||
...options,
|
||||
variant: undefined,
|
||||
yesthreads: !iOS || modernIOS,
|
||||
base: '/_libav'
|
||||
});
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import FFmpegWorker from "$lib/task-manager/workers/ffmpeg?worker";
|
||||
|
||||
import { device } from "$lib/device";
|
||||
import { killWorker } from "$lib/task-manager/run-worker";
|
||||
import { updateWorkerProgress } from "$lib/state/task-manager/current-tasks";
|
||||
import { pipelineTaskDone, itemError, queue } from "$lib/state/task-manager/queue";
|
||||
@ -34,7 +35,11 @@ export const runFFmpegWorker = async (
|
||||
startAttempts++;
|
||||
if (startAttempts <= 10) {
|
||||
killWorker(worker, unsubscribe, startCheck);
|
||||
return await runFFmpegWorker(workerId, parentId, files, args, output, variant);
|
||||
return await runFFmpegWorker(
|
||||
workerId, parentId,
|
||||
files, args, output,
|
||||
variant, device.supports.multithreading
|
||||
);
|
||||
} else {
|
||||
killWorker(worker, unsubscribe, startCheck);
|
||||
return itemError(parentId, workerId, "queue.worker_didnt_start");
|
||||
|
@ -1,7 +1,13 @@
|
||||
import LibAVWrapper from "$lib/libav";
|
||||
import type { FileInfo } from "$lib/types/libav";
|
||||
|
||||
const ffmpeg = async (variant: string, files: File[], args: string[], output: FileInfo) => {
|
||||
const ffmpeg = async (
|
||||
variant: string,
|
||||
files: File[],
|
||||
args: string[],
|
||||
output: FileInfo,
|
||||
yesthreads: boolean
|
||||
) => {
|
||||
if (!(files && output && args)) {
|
||||
self.postMessage({
|
||||
cobaltFFmpegWorker: {
|
||||
@ -25,7 +31,7 @@ const ffmpeg = async (variant: string, files: File[], args: string[], output: Fi
|
||||
})
|
||||
});
|
||||
|
||||
ff.init({ variant });
|
||||
ff.init({ variant, yesthreads });
|
||||
|
||||
const error = (code: string) => {
|
||||
self.postMessage({
|
||||
@ -121,7 +127,7 @@ const ffmpeg = async (variant: string, files: File[], args: string[], output: Fi
|
||||
|
||||
self.onmessage = async (event: MessageEvent) => {
|
||||
const ed = event.data.cobaltFFmpegWorker;
|
||||
if (ed?.variant && ed?.files && ed?.args && ed?.output) {
|
||||
await ffmpeg(ed.variant, ed.files, ed.args, ed.output);
|
||||
if (ed?.variant && ed?.files && ed?.args && ed?.output && ed?.yesthreads) {
|
||||
await ffmpeg(ed.variant, ed.files, ed.args, ed.output, ed.yesthreads);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user