mp4-tag is an open sourced JavaScript library used to view and edit the metadata of MP4 media files.
You can explore the examples directory to show how to use the library.
- Read and write MP4 metadata
- Easy to use
You can download the ready-to-use script at
GitHub releases or you can
build your own by cloning this repository using git
then build it.
git clone https://github.com/eidoriantan/mp4-tag
cd ./mp4-tag
npm install
npm run build
You can also install this package by using npm
:
npm install --save mp4-tag@latest
If you are using browser, you can just install the library through a CDN:
<script src="https://cdn.jsdelivr.net/npm/mp4-tag@latest/dist/mp4-tag.min.js">
For browsers:
<input type="file" id="input-file" accept="video/mp4">
<script>
const inputFile = document.getElementById('input-file')
inputFile.onchange = function () {
const reader = new FileReader()
reader.onload = function () {
const buffer = this.result
const mp4tag = new MP4Tag(buffer)
mp4tag.read()
// Handle error if there's any
if (mp4tag.error !== '') throw new Error(mp4tag.error)
else console.log(mp4tag.metadata)
}
if (this.files.length > 0) {
reader.readAsArrayBuffer(this.files[0])
}
}
</script>
For Node.js:
const MP4Tag = require('mp4-tag')
const fs = require('fs')
const buffer = fs.readFileSync('/path/to/video.mp4')
const mp4tag = new MP4Tag(buffer)
mp4tag.read()
// Handle error if there's any
if (mp4tag.error !== '') throw new Error(mp4tag.error)
else console.log(mp4tag.tags)
If you had found a bug or any unexpected behavior, you can submit an issue through GitHub issues.