Skip to content

qq15725/modern-mp4

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

modern-mp4

Minzip Version Downloads Issues License

Install

npm i modern-mp4

# peerDependencies
npm i mp4box

Usage

Encode

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

Decode

import { decode } from 'modern-mp4'

const infoWithFrames = await decode({
  // string | Blob | BufferSource | Array<BufferSource> | readableStream<BufferSource>
  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)