Skip to main content

Pause, resume and abort conversion

You can pause, resume and abort the conversion process.

Create a webcodecsController() and use the following methods:

Pause and resume

Pause and resume
tsx
import {webcodecsController, convertMedia} from '@remotion/webcodecs';
 
const controller = webcodecsController();
 
convertMedia({
src: 'https://www.w3schools.com/html/mov_bbb.mp4',
container: 'webm',
controller,
})
.then(() => {
console.log('Finished downloading');
})
.catch((err) => {
console.error('Error downloading', err);
});
 
// Wait 1 sec, pause, wait 1 sec, resume
await new Promise((resolve) => setTimeout(resolve, 1000));
controller.pause();
await new Promise((resolve) => setTimeout(resolve, 1000));
controller.resume();

Cancel a conversion

Cancel a conversion process
tsx
import {webcodecsController, convertMedia} from '@remotion/webcodecs';
 
const controller = webcodecsController();
 
convertMedia({
src: 'https://www.w3schools.com/html/mov_bbb.mp4',
container: 'webm',
controller,
})
.then(() => {
console.log('Finished parsing');
})
.catch((err) => {
console.error('Error parsing', err);
});
 
// Cancel after 10 seconds
await new Promise((resolve) => setTimeout(resolve, 10_000));
controller.abort();

Checking if a conversion was aborted

Use the hasBeenAborted() function to check if a conversion was aborted using the .abort() method.

Checking if a conversion was aborted
tsx
import {hasBeenAborted} from '@remotion/media-parser';
import {webcodecsController, convertMedia} from '@remotion/webcodecs';
 
const controller = webcodecsController();
 
const promise = convertMedia({
src: 'https://www.w3schools.com/html/mov_bbb.mp4',
container: 'webm',
controller,
})
.then(() => {
console.log('Finished conversion');
})
.catch((err) => {
if (hasBeenAborted(err)) {
console.log('Conversion was cancelled');
} else {
console.error('Error converting', err);
}
});

See also