ffmpegwasm / ffmpegwasm/ffmpeg.wasm

[Feature] Cancel a running job

Abierto
#187 7 comentarios 5 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
C
Estrellas
17.8k
Forks
1.1k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

**Is your feature request related to a problem? Please describe.**
I'm making a browser extension that uses this module, and the user might want to cancel an occurring FFmpeg job at any time, which is not currently possible.

**Describe the solution you'd like**
```ts
ffmpeg.abort();
```

**Describe alternatives you've considered**
My current somewhat-working [workaround](https://gist.github.com/pygy/6290f78b078e22418821b07d8d63f111#gistcomment-3408351) is:
```ts
class CancellablePromise {
private readonly symbolAbort = Symbol("cancelled");
private readonly promiseAbort: Promise;
private resolve!: Function; // Works due to promise init

constructor() {
this.promiseAbort = new Promise(resolve => (this.resolve = resolve));
}

public async wrap(promise: PromiseLike): Promise {
const result = await Promise.race([promise, this.promiseAbort]);
if (result === this.symbolAbort) {
throw new Error("Aborting FFmpeg");
}

return result;
}

public abort() {
this.resolve(this.symbolAbort);
}
}
```
Then, in the code:
```ts
import { createFFmpeg } from "@ffmpeg/ffmpeg";

const ffmpeg = createFFmpeg({ log: true });

chrome.runtime.onConnect.addListener(async port => {
if (port.name === "run-ffmpeg-job") {
if (!ffmoeg.isLoaded()) {
await ffmpeg.load();
}

const promise = new CancellablePromise();
ffmpeg.FS("writeFile", "filename.mp4");
const promiseJob = promise.wrap(ffmpeg.run("-i", "filename.mp4", /*...*/));

port.onDisconnect.addListener(() => {
promise.abort();
});

await promiseJob;
}
});
```
The problem with `promise.abort()` is that FFmpeg will still run (output will still flow to the console).

**Additional context**

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.