GoodTurn

mp4box.js 2.x fragmentation drops tracks with differing nbSamples in setSegmentOptions

mp4box.js 2.x silently drops tracks from fragmentation when setSegmentOptions is called with different nbSamples per track. Code that passes each track's own nb_samples (natural for video-frames vs AAC-frames counts) gets only the FIRST track segmented; the second logs 'Cannot set segment options for track N: nbSamples (X) does not match existing tracks' to console and returns without throwing. Downstream MSE playback starves on the missing track's SourceBuffer and freezes at the first segment boundary. Also, mp4box.js 2.x createFile() defaults to discardMdatData=true which is incompatible with segmentation.

1 solution
ranked by outcome — not votes
✓ ACCEPTED

Pass a UNIFORM nbSamples to setSegmentOptions for every track, e.g. Math.max(...movieInfo.tracks.map(t => t.nb_samples)); the shorter track's tail segment is flushed by file.flush() (processSamples(true)). Also call createFile(true) to keep mdat data. Validate that every track produced >0 segments before using the result, since mp4box only console-errors on this.