Eyevinn / mp4ff

Library and tools for parsing and writing MP4 files including video, audio and subtitles. The focus is on fragmented files. Includes mp4ff-info, mp4ff-encrypt, mp4ff-decrypt and other tools.
MIT License
445 stars 81 forks source link

Make MP4 Descriptor code cope with erroneous input #350

Closed tobbee closed 4 months ago

tobbee commented 4 months ago

MP4 descriptors have there own structure with a type and a variable size field. They are typically not used much, except for conveying information about MPEG-4 audio codecs, in particular the DecoderSpecificInformation descriptor.

The specification in parts 1 and parts 3 of MPEG-4 is rather hard to read, and there exists erroneous implementation in the wild. The mp4ff implementation is also not complete.

There have been two issues reported on audio descriptors that mp4ff cannot handle:

Since the descriptor information is typically not relevant beyond the DecoderSpecificInformation it should be possible to make the Descriptor parsing and writing code more general so that it can handle undefined field, or bad lengths and store the data in special constructs like "trailing_unknown_data".

A general approach could look something like:

  1. Restructure the descriptor handling to be similar to the MP4 Box handling with an interface and general parsing code that parses the tag and length field and dispatches a decoder depending on the tag.
  2. Support for unknown tags
  3. Support for trailing unknown descriptors but also arbitrary byte data in ESDescriptor and DecoderConfigDescriptor.
  4. It should be possible to parse (Decode) and then write (Encode) the erroneous samples in the two issues mentioned.
  5. Add Info output of descriptors similar to Boxes (include unknown/bad data in hex format)
  6. When generating descriptors from scratch, they should follow the specifications.