mp4box.js icon indicating copy to clipboard operation
mp4box.js copied to clipboard

Feature Request: View mdat Data

Open dukesook opened this issue 6 months ago • 7 comments

I'm interested in viewing various mdat data, including:

  • Image Items
  • Metadata Items (grid, exif, & mime)
  • Video Tracks
  • Sample metadata from the saiz/saio boxes

Do these seem within scope for MP4Box?

dukesook avatar May 27 '25 16:05 dukesook

The File Reader example demonstrates many features of MP4Box.js. Does that help you? If not, what's missing?

DenizUgur avatar May 27 '25 16:05 DenizUgur

The File Reader doesn't show any information stored in the mdat box.

For example, it may show an item of type grid, but the grid data itself is hidden in the mdat:

aligned(8) class ImageGrid {
  unsigned int(8) version = 0;
  unsigned int(8) flags;
  unsigned int FieldLength = ((flags & 1) + 1) * 16; // this is a temporary, non-parsable variable
  unsigned int(8) rows_minus_one;
  unsigned int(8) columns_minus_one;
  unsigned int(FieldLength) output_width;
  unsigned int(FieldLength) output_height;
}

dukesook avatar May 27 '25 17:05 dukesook

Oh I see, yeah there is no parsing/decoding for mdat right now. You have access to the individual samples but no information as you described.

PRs always welcome as this is not something we have considered.

DenizUgur avatar May 27 '25 17:05 DenizUgur

Okay, I'll try putting together a PR for this.

On a similar note, has there been consideration into turning MP4Box into a player? I see the main index.html file already plays video given a URL. Is there any reason why this couldn't be extended to play a local file?

dukesook avatar May 27 '25 18:05 dukesook

The demos haven't been updated in a while but you can definitely use MP4Box.js as a player, either connect it to a video element with MSE (as seen here) or use onSamples callback and decode the samples via VideoDecoder.

If your concern is that why you can't just use MP4Box.js to play a file, what would MP4Box.js do differently than just using <video src="input.mp4" />

DenizUgur avatar May 27 '25 18:05 DenizUgur

If your concern is why you can't just use MP4Box.js to play a file, what would MP4Box.js do differently than just using <video src="input.mp4" />?

The HTML video tag and most other players have some limitations that MP4Box.js might be able to overcome. For example, say a file has a mix of multiple video tracks and images and the user wants to browse through and play each one.

There's also various codecs that aren't yet supported (J2K, HTJ2K, etc). Playing such files in MP4Box.js would require some decoding library which I'm not sure if there's interest in adding. I'm particularly interested in playing uncompressed MP4s/HEIFs which again isn't supported in most players.

dukesook avatar May 27 '25 19:05 dukesook

You have onSamples callback that gives you samples per track. It shouldn't be the responsibility of this library to decode the samples. Maybe some sort of plugin based architecture could be employed to decode them if needed.

That requires some considerable planning though. Although, I can see the benefit of having that feature. We recently went through a complete rewrite. Once the dust settles on that stuff we could consider how such an architecture could be implemented.

DenizUgur avatar May 27 '25 20:05 DenizUgur