Video editor: the JavaScript library
Video editing in the browser on WebCodecs: trim, convert to MP4, WebM or MKV, make a GIF, extract the sound, change speed, size, rotation, apply filters and add captions. The file never leaves the computer and no codec is downloaded.
@openlibsdev/video-editor- v1.0.0
- ES module
- MIT
Installation
With a bundler or Node-style imports:
npm install @openlibsdev/video-editorimport VideoEditor from "@openlibsdev/video-editor";Or straight in a page, without a build step (jsDelivr resolves the dependencies):
<script type="module">
import VideoEditor from "https://cdn.jsdelivr.net/npm/@openlibsdev/video-editor@1.0.0/+esm";
</script>Usage
import VideoEditor from "@openlibsdev/video-editor";
const file = document.querySelector("input[type=file]").files[0];
const engine = VideoEditor.createEngine();
const info = await engine.probe(file); // { duration, width, height, hasAudio, ... }
const job = VideoEditor.normalize({ op: "trim", start: 1, end: 3 }, info.duration);
const result = await engine.run(file, job, {
hasAudio: info.hasAudio,
onProgress: p => console.log(Math.round(p * 100) + "%")
});
console.log(result.name, result.blob.size); // a new file, e.g. clip_trim.mp4API
VideoEditor.createEngine()
Creates the processing engine; see its methods below.
VideoEditor.normalize(job, duration)
Checks a job and fills in defaults: {op, start, end, format, speed, …}; the times are clamped to the video length.
VideoEditor.buildJob(job, info)
Turns a job into a plan: what is decoded, changed and encoded, and the name and type of the result.
VideoEditor.OPS
The operations: trim, convert, gif, audio, speed, resize, rotate, filter, text.
VideoEditor.DEFAULTS
Default values of every job field.
VideoEditor.FORMATS
Output video containers.
VideoEditor.AUDIO_FORMATS
Output sound formats.
VideoEditor.FILTERS
Picture filters: grayscale, sepia, brighter, contrast, invert, blur, sharpen, vignette.
VideoEditor.VIDEO_CODECS
Video codecs tried in order of preference for each container.
VideoEditor.AUDIO_CODECS
Audio codecs tried in order of preference for each container.
VideoEditor.applyFilter(img, name)
Applies a filter to an ImageData frame.
VideoEditor.stretchAudio(channels, sampleRate, speed)
Changes the speed of sound without changing its pitch (WSOLA).
VideoEditor.timecode(sec)
Seconds → "h:mm:ss.s".
VideoEditor.parseTimecode(text)
"1:02.5" or "62.5" → seconds.
VideoEditor.captionFamilies()
Font families available for captions.
VideoEditor.sizeText(bytes, units)
File size as text ("12.4 MB").
VideoEditor.APP
Name, version and release date of the library: {name, version, created}.
VideoEditor.GIF_FPS
Frame rates offered for a GIF.
VideoEditor.GIF_WIDTHS
Widths offered for a GIF, in pixels.
VideoEditor.HEIGHTS
Frame heights offered for resizing, in pixels (the video is never enlarged).
VideoEditor.MIME
MIME type of each output extension.
VideoEditor.ROTATIONS
Rotations and flips: cw, ccw, 180, hflip, vflip.
VideoEditor.TEXT_POSITIONS
Positions of a caption: top, center, bottom.
VideoEditor.baseName(name)
File name without its extension, with characters not allowed in file names replaced.
VideoEditor.captionTextFontData
Data for the caption's text and font block (font-forge's, limited to fonts usable for captions).
VideoEditor.extOf(name)
Extension of a file name in lower case ("mp4" when there is none).
VideoEditor.findNamedColor(text, lang)
Finds a named color by its name in the given language ("dark blue" → #00008b).
VideoEditor.fontFor(family, bold, italic)
Browser font name of a family and style, loading it first.
VideoEditor.listNamedColors(lang)
Lists the named colors with their names in the given language.
VideoEditor.namedColorTexts(lang)
Labels of the color field in the given language (the texts of the color picker), English for a missing language.
VideoEditor.textFontData
Data for a text and font block: the font list, loading a font style, adding a font file, the block's labels in a language and the default values.
Instance: engine = VideoEditor.createEngine()
engine.probe(file, opts)
Reads a file: duration, size, codecs and whether it has sound and picture.
engine.run(file, job, opts)
Processes a file by a job and returns {blob, name, mime, ext, plan, codecs}. Options: hasAudio, frameHeight, onProgress, onLog, signal.
engine.load()
Prepares the engine in advance (otherwise the first call does it).
engine.terminate()
Stops the current job.
engine.loaded
Whether the engine is ready.
Dependencies
What the library loads, with the licenses (all are listed on the Licenses page).
| Name | Version | License | Files |
|---|---|---|---|
| @openlibsdev/font-forge | 1.0.0 | MIT | GitHub |
| @openlibsdev/image-forge | 1.0.0 | MIT | GitHub |
| @breezystack/lamejs | 1.2.7 | LGPL-3.0 | License · Source code |
| @imagemagick/magick-wasm | 0.0.35 | Apache-2.0 | License · Source code |
| @imagemagick/magick-wasm | 0.0.35 | Apache-2.0 | License · Source code |
| @simonwep/pickr | 1.10.2 | MIT | License · Source code |
| @simonwep/pickr | 1.10.2 | MIT | License · Source code |
| dejavu-fonts-ttf | 2.37.3 | Bitstream Vera Fonts License (free, redistributable); DejaVu changes are public domain | License · Source code |
| gifenc | 1.0.3 | MIT | License · Source code |
| imagetracerjs | 1.2.6 | Unlicense | License · Source code |
| mediabunny | 1.66.0 | MPL-2.0 | License · Source code |