media-trimmer
v0.0.1
Published
A simple mp4 video trimmer using the WebCodecs API
Downloads
143
Maintainers
Readme
A video trimmer in the browser
https://demo.miru.media/trim/
npm install media-trimmer
import { trim } from 'media-trimmer'
try {
// The input video must be a `.mp4`/`.mov` file with a video track
// and the browser must support video encoding with the WebCodecs API
await trim('video.mp4', {
start: 2, // start time in seconds
end: 10, // end time in seconds
mute: false, // ignore the audio track?
})
} catch (error) {
alert(error)
}
It also comes with a Web Component UI:
<!-- after importing the library, the <media-trimmer> custom element will be defined -->
<media-trimmer id="trimmer" source="video.mp4"></media-trimmer>
<button id="export" type="buton">Get trimmed video</button>
<script>
const trimmer = document.getElementById('trimmer')
const export = document.getElementById('export')
button.addEventListener('click', () => console.log(await trimmer.toBlob()))
trimmer.addEventListener('progress', (event) => console.log('progress:', event.detail.progress))
<script>
Powered by:
Roadmap
- [ ] Lossless trimming
- [ ] Bitrate/filesize controls
- [ ] Webm support
- [ ] Color profile preservation
- [ ] Increased browser and codec support via LibAVJS-WebCodecs-Polyfill
Funding
This project is funded through NGI Zero Core, a fund established by NLnet with financial support from the European Commission's Next Generation Internet program. Learn more at the NLnet project page.