Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse user metadata #356

Open
tobiasBora opened this issue Sep 19, 2023 · 0 comments
Open

Parse user metadata #356

tobiasBora opened this issue Sep 19, 2023 · 0 comments
Labels

Comments

@tobiasBora
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants