ffmpegwasm / ffmpegwasm/ffmpeg.wasm

[Feature] Cancel a running job

Đang mở
#187 7 bình luận 5 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
C
Star
17.8k
Fork
1.1k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

**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**

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.