0.1.0-beta • Published 11 months ago

mp4-tag v0.1.0-beta

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Node.js CI npm Maintenance

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.

Features

  • Read and write MP4 metadata
  • Easy to use

Installation

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

Usage

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)

Support

If you had found a bug or any unexpected behavior, you can submit an issue through GitHub issues.

0.1.0-beta

11 months ago