/* eslint-disable @typescript-eslint/no-explicit-any */ import Piscina from 'piscina'; import { VideoInfo } from './video'; type EncodeArgs = { method: 'extractThumbnail' | 'convertFile' | 'convert' | 'getVideoInfo'; args: any[]; }; type EncodeResult = any; async function getWorkerPath() { return new URL(/* @vite-ignore */ './ffmpeg-worker.mjs', import.meta.url).href; } export class FFmpegService { public static async extractThumbnail(videoPath: string, thumbnailPath: string): Promise { const piscina = new Piscina({ filename: await getWorkerPath(), }); await piscina.run({ method: 'extractThumbnail', args: [videoPath, thumbnailPath] }); await piscina.destroy(); } public static async convertFile(inputFile: string, outputFile: string, format: string): Promise { const piscina = new Piscina({ filename: await getWorkerPath(), }); await piscina.run({ method: 'convertFile', args: [inputFile, outputFile, format] }); await piscina.destroy(); } public static async convert(filePath: string, pcmPath: string): Promise { const piscina = new Piscina({ filename: await getWorkerPath(), }); const result = await piscina.run({ method: 'convert', args: [filePath, pcmPath] }); await piscina.destroy(); return result; } public static async getVideoInfo(videoPath: string, thumbnailPath: string): Promise { const piscina = new Piscina({ filename: await getWorkerPath(), }); const result = await piscina.run({ method: 'getVideoInfo', args: [videoPath, thumbnailPath] }); await piscina.destroy(); return result; } }