[Feature] Cancel a running job
See original GitHub issueIs 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
ffmpeg.abort();
Describe alternatives you’ve considered My current somewhat-working workaround is:
class CancellablePromise {
private readonly symbolAbort = Symbol("cancelled");
private readonly promiseAbort: Promise<any>;
private resolve!: Function; // Works due to promise init
constructor() {
this.promiseAbort = new Promise(resolve => (this.resolve = resolve));
}
public async wrap<T>(promise: PromiseLike<T>): Promise<T> {
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:
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
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Cancel a Running Job - TechDocs - Broadcom Inc.
Select. Jobs. from the. Monitor. menu. · Select the job that you want to cancel, and select. Cancel active job. from the. JOB....
Read more >Cancel a Running Job - Analytics Cloud - Oracle Help Center
Click the Cancel Running Jobs icon at the top of the table. Click OK in the confirmation message.
Read more >Force Cancel a Job or Task - Job Manager | Microsoft Learn
When a task is force canceled, the task and its sub-tasks skip the grace period and are stopped immediately.
Read more >Best way to implement graceful cancel for running async jobs ...
Provide it jobs that will be run asynchronously and could return a result; Shutdown the executor so that all running jobs are cancelled....
Read more >Ability to cancel running jobs? · Issue #684 · rq/rq - GitHub
If it gets a cancel command it will call the stop command of the worker. Has anyone implemented something like this already? Will...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
createFFmpeg()
andffmpeg.load()
After calling
ffmpeg.exit()
, any code that was after theffmpeg.run()
isn’t being executed, even if I wrap the whole FFmpeg code block intry-catch
Think like:The
someCode()
part will not execute ifelCancel
’s callback gets executedHow do I make a code execute afterward?