From 2d603cee1c9ca2d4837a969978fbdc514e9e85b5 Mon Sep 17 00:00:00 2001 From: lyonbot Date: Mon, 22 Apr 2024 21:37:39 +0800 Subject: [PATCH] feat: abort ffmpeg --- src/components/Processing.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/Processing.tsx b/src/components/Processing.tsx index 2d5b815..521571b 100644 --- a/src/components/Processing.tsx +++ b/src/components/Processing.tsx @@ -1,4 +1,4 @@ -import { Show, createSignal } from "solid-js"; +import { Show, createEffect, createRoot, createSignal } from "solid-js"; import { encode as GIFEncode } from 'modern-gif' import GIFWorkerJS from 'modern-gif/worker?url' import { outputSize, outputTimeRange, store, updateStore } from "../store"; @@ -113,6 +113,16 @@ export function ProcessingBar() { // use WebCodec to decode file, which is much faster! const stage1Filename = 'medium.raw' const stage1DecodeArgs: string[] = [] + const abortSignal = createRoot((dispose) => { + const controller = new AbortController() + createEffect(() => { + if (!isRunning()) { + controller.abort() + dispose() + } + }) + return controller.signal + }) { const { width, height, frameCount, combined } = await grabFramesAndCombine() @@ -136,7 +146,7 @@ export function ProcessingBar() { '-i', stage1Filename, '-vf', `split[a][b];[a]palettegen=max_colors=${options.maxColors}[pal];[b][pal]paletteuse=dither=${options.dither}`, '-y', outputFilename - ]) + ], undefined, { signal: abortSignal }) console.log('stage2 exit code = ' + stage2Out) // const argsRaw = [