An open API service indexing awesome lists of open source software.

https://github.com/qq15725/modern-mp4

🚀 JavaScript MP4 Codec.
https://github.com/qq15725/modern-mp4

decoder encoder mp4 mp4box webcodec

Last synced: about 1 year ago
JSON representation

🚀 JavaScript MP4 Codec.

Awesome Lists containing this project

README

          

modern-mp4



Minzip


Version


Downloads


Issues


License

## Install

```shell
npm i modern-mp4

# peerDependencies
npm i mp4box
```

## Usage

### Encode

```ts
import { encode } from 'modern-mp4'

const blob = await encode({
width: 1280,
height: 720,
audio: false,
frames: [
// data: string | CanvasImageSource | VideoFrame | AudioData
{ data: '/example1.png', duration: 3000 },
{ data: '/example2.png', duration: 3000 },
],
})

window.open(URL.createObjectURL(blob))
```

### Encoder

```ts
import { MP4Encoder } from 'modern-mp4'

const encoder = new MP4Encoder({
width: 1280,
height: 720,
audio: false,
framerate: 30,
})

await encoder.encode({
data: '/example1.png',
timestamp: 0,
duration: 33,
})

await encoder.encode({
data: '/example1.png',
timestamp: 33,
duration: 66,
})

const blob = await encoder.flush()

window.open(URL.createObjectURL(blob))
```

### Decode

```ts
import { decode } from 'modern-mp4'

const infoWithFrames = await decode({
// string | Blob | BufferSource | Array | readableStream
data: './example.mp4',
audio: false,
// framerate: 10,
// onInfo: info => console.log(info),
// onFrame: frame => { console.log(frame) },
// onProgress: (current, total) => console.log(`decode frame ${current}/${total}`),
})

console.log(infoWithFrames)
```