web/ffmpeg: define multithreading support outside of web worker context
Some checks are pending
CodeQL / Analyze (${{ matrix.language }}) (none, javascript-typescript) (push) Waiting to run
Run tests / check lockfile correctness (push) Waiting to run
Run tests / web sanity check (push) Waiting to run
Run tests / api sanity check (push) Waiting to run

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:
wukko 2025-06-29 13:45:39 +06:00
parent b2c5c42ae3
commit 9cc551008d
No known key found for this signature in database
GPG Key ID: 3E30B3F26C7B4AA2
3 changed files with 16 additions and 12 deletions

View File

@ -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'
});
}

View File

@ -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");

View File

@ -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);
}
}