Parse user metadata

Open
#356 1 comment 3 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
22/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Domain
data

Research direction

This is a usage question about walking MP4 udta/ilst boxes: the sample calls mp4boxFile.getBoxes("ilst") and then dumps the raw payload with TextDecoder, and asks whether ilst is the only box holding user metadata such as comments. Start in the box-parsing sources (the udta/meta/ilst box definitions and getBoxes) to see whether ilst children are exposed as parsed boxes or only as raw data, and test with a file that carries a comment atom. Done means a documented, correct way to read comment metadata, or a small parser improvement, rather than manual byte decoding.

Written by the indexing model from the issue text.

Description

question

I’m trying to get the users metadata of a video (comment notably). I tried to do something like that:

<!DOCTYPE html>
<html>
  <head>
    <title>MP4 Metadata Extraction</title>
  </head>
  <body>
    <input type="file" id="fileInput" accept=".mp4">
    <div id="metadataDisplay"></div>

    <script src="mp4box.all.js"></script>
    <script>
      document.getElementById("fileInput").addEventListener("change", function (e) {
        const file = e.target.files[0];
        if (file) {
          const reader = new FileReader();

          reader.onload = function (e) {
            const arrayBuffer = e.target.result;

            // Initialize mp4box
            const mp4boxFile = MP4Box.createFile();
            mp4boxFile.onReady = (info) => {
              console.log("READY");
              console.log(info);
            };
            mp4boxFile.onError = () => {
              console.log("Error");
            };
            // Create a Blob from the ArrayBuffer
            /* const blob = new Blob([arrayBuffer]);
             */
            console.log("created blob");

            // Read the Blob using mp4box
            arrayBuffer.fileStart = 0;
            mp4boxFile.appendBuffer(arrayBuffer);

            // Get metadata, ilst is inside udta, and seems to be the one with comments (maybe others could as well?)
            /* const udtaBoxes = mp4boxFile.getBoxes("udta"); */
            const ilstBoxes = mp4boxFile.getBoxes("ilst");

            const decoder = new TextDecoder('utf-8');
            ilstBoxes.forEach( (ilstBox) => {
              console.log(decoder.decode(ilstBox.data));
            });
          };
          reader.readAsArrayBuffer(file);
        }
      });
    </script>
  </body>
</html>

and I’m close enough to get the content, but I’m not sure how to parse it further, and I’m not sure if this is the only box that can contain user content. Is there a simpler way to get user metadata, like comments?

Dominant language
TypeScript
Stars
2.5k
Forks
390
Avg merge
1d 17h
Merged PRs (30d)
8

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from gpac/mp4box.js

All issues in gpac/mp4box.js

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.