Skip to content

FragmentedMp4Muxer: add support for sidx and mfra boxes to enable seekability in fragmented MP4 output #3208

@mmilazzo-telsy

Description

@mmilazzo-telsy

Use case description

The FragmentedMp4Muxer currently does not write a sidx nor a mfra box in the produced fragmented MP4 files.

As a result, FragmentedMp4Extractor cannot treat these files as seekable (VLC or even the iOS player can play files without these boxes, I don't know how they do it).

This is a significant limitation when the output file is intended for local playback or any use case that requires seeking (e.g. trimming, re-muxing, or progressive download scenarios where the full file is available).

Proposed solution

Add an option to FragmentedMp4Muxer (or enable it by default) to write one or both of the following boxes:

sidx — written after the moov box, before the first moof, providing a compact byte-range index per segment. This is the preferred approach for streaming-friendly files (DASH, etc.) but it would strictly require a seekable file when muxing.
mfra — written at the end of the file, containing a mfro (Movie Fragment Random Access Offset) and one or more tfra (Track Fragment Random Access) boxes. This is simpler to produce since all offsets are known at finalization time and would not require seeking on the outputfile.

Adding either box would allow FragmentedMp4Extractor to recognize the file as seekable and enable full random-access playback via ExoPlayer/Media3.

Alternatives considered

See how VLC allows to seek even if those boxes are not present, maybe it uses more approssimative methods. This would maximize compatibility.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions