Skip to content

feat: add per-track segmentation init mode#549

Open
lideen wants to merge 1 commit into
gpac:mainfrom
lideen:feat/per-track-init-segmentation
Open

feat: add per-track segmentation init mode#549
lideen wants to merge 1 commit into
gpac:mainfrom
lideen:feat/per-track-init-segmentation

Conversation

@lideen
Copy link
Copy Markdown
Contributor

@lideen lideen commented Feb 23, 2026

Summary

This PR adds a new segmentation initialization mode to support one init segment per fragmented track while preserving the existing combined-init behavior.

The main motivation is Media Source Extensions (MSE) integration: playback setups that require simultaneous multi-audio playback need one MediaSource (containing its SourceBuffer) per track, which in turn requires one init segment per track instead of a single combined init segment.

Note

This behavior aligns with historical usage, per-track initialization used to be the default behavior.
It stopped being the default in commit 77247e1 (fix: segmenting will also multiplex the fragmented tracks, Jul 8, 2025), first released in v1.3.1.

initializeSegmentation now supports:

  • initializeSegmentation() / initializeSegmentation('combined') (default):
    returns a single init segment containing all selected fragmented tracks.
  • initializeSegmentation('per-track'):
    returns one init segment per selected fragmented track.

Documentation

Updated README.md segmentation docs (it seems to have been stale documenting the old behavior before 77247e1):

  • documented initializeSegmentation(mode) with supported values ('combined' and 'per-track')
  • updated examples to reflect current return shapes
  • fixed the setSegmentOptions anchor link

@DenizUgur
Copy link
Copy Markdown
Member

@lideen Could you resolve the conflicts and add a changeset? I can then merge this, thanks.

@lideen lideen force-pushed the feat/per-track-init-segmentation branch from a9613c4 to d2f3e15 Compare May 25, 2026 11:15
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 25, 2026

🦋 Changeset detected

Latest commit: ddeed03

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
mp4box Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@lideen lideen force-pushed the feat/per-track-init-segmentation branch from d2f3e15 to 16b15bd Compare May 25, 2026 11:19
@lideen lideen force-pushed the feat/per-track-init-segmentation branch from 16b15bd to ddeed03 Compare May 25, 2026 11:20
@lideen
Copy link
Copy Markdown
Contributor Author

lideen commented May 25, 2026

@DenizUgur

@lideen Could you resolve the conflicts and add a changeset? I can then merge this, thanks.

done, thanks


// Write the initialization segments to the output stream
out.insertBuffer(init.buffer);
out.insertBuffer(MP4BoxBuffer.fromArrayBuffer(init.buffer, offset));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also revert these changes? Were TypeScript complaining without it? If not, could you also make sure your new tests are using the same syntax?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants