Commit Graph
79 Commits
Author SHA1 Message Date
Vanilagy 3fc69490f5 Suppress range request warning for HLS-adjacent requests (closes #354) 2026-04-21 15:12:34 +02:00
Vanilagy 783cfa6fbe Add AppendOnlyStreamSource, adjust examples to use it 2026-04-21 14:58:33 +02:00
Vanilagy 2b3e5f45c6 Remove createInputFrom, changed meaning of PathedSource, add CustomPathedSource 2026-04-21 13:22:10 +02:00
77e70f9090 Add BufferTarget.onFinalize, OutputOptions.onFinalize, ConcurrentRunner (#349)
* Add BufferTarget.onFinalize option for awaitable async action on finalize

The `finalized` event fires synchronously and its return value is ignored,
making it unsuitable for use cases where the muxer should wait (e.g.
uploading the buffer to S3, R2, or other object stores that require a
known Content-Length and therefore can't stream via StreamTarget).

Adds a new `BufferTargetOptions` type with an `onFinalize` callback that
the muxer awaits before resolving. Matches the existing callback pattern
used by `HlsOutputFormatOptions.onSegment`, `onMaster`, etc.

When used with PathedTarget, this provides proper backpressure: the next
segment won't start being produced until the previous one has finished
uploading, keeping memory bounded regardless of video length.

- Adds `BufferTargetOptions` type, exported from the package root
- `BufferTarget` constructor now accepts optional options (backward compatible)
- `_finalize()` awaits `onFinalize` before emitting the `finalized` event
- Adds runtime validation for non-function callbacks
- Updates "Upload to a server" docs in writing-hls.md with S3 pattern
- Documents `onFinalize` in writing-media-files.md BufferTarget section
- Adds tests for callback invocation, async awaiting, backward compat, and validation

* Add ConcurrentRunner, add OutputOptions.onFinalize, adjust docs accordingly, clean up tests

* give me more control baby

* forgot to tell about it

* polish guide and js docs

* vanilagy says remove this, docs will reveal it

---------

Co-authored-by: Vanilagy <[email protected]>
2026-04-17 18:42:09 +02:00
Vanilagy 95e9dc5210 MORE CODE REVIEW 2026-04-16 18:27:51 +02:00
Vanilagy b85ecd3109 Code review fixes 2026-04-16 17:43:12 +02:00
Vanilagy 56b25fbdf8 Add onSegmentPopped, add more tests, improve validation, improve M3U8 grammar 2026-04-16 14:48:57 +02:00
Vanilagy f99adf2208 Optimize media tag codec parsing, add a test for it, extract tag strings into constants 2026-04-16 11:31:43 +02:00
Vanilagy 2d0aac3208 Fix HLS demuxer parsing bug, extract HLS mime type out, add TargetRequest.mimeType 2026-04-16 10:53:36 +02:00
Vanilagy 8241820a4f Remove unnecessary sync getters 2026-04-15 09:16:40 +02:00
Vanilagy a3767af141 Fix HLS muxer audio segmentation bug, fix conversion tests failing in CI 2026-04-14 21:40:07 +02:00
Vanilagy 2a2b6450c9 Add better doc blocks, special deprecated logic for API doc generation, add multi-tiered SegmentedInput hydration for reducing file request count, ditch VirtualInputFormat indirection 2026-04-13 17:25:46 +02:00
Vanilagy 051578c2ca Remove input track descriptors, add async getters on tracks for everything, deprecate old sync getters 2026-04-10 16:23:17 +02:00
Vanilagy aa810fc433 Fix SourceRef race conditions, fix "source" and "target" getter returning unused instances, add missing validation, make "getDurationFromMetadata" only exist on tracks, fix examples, expand media player to support live playback, change the signatures of some Input APIs 2026-04-10 13:38:14 +02:00
Vanilagy 0813bcab28 Add missing doc blocks for everything, add PathedTarget and PathedSource, few other changes & fixes 2026-04-09 15:22:45 +02:00
Vanilagy fdb5f4102f Add new createInputFrom helper function 2026-04-08 14:52:27 +02:00
Vanilagy bee1518100 Add TrackDescriptor concept 2026-04-08 12:21:08 +02:00
Vanilagy 3c0a6fc299 Fix failing tests, add missing license headers 2026-04-01 16:39:42 +02:00
Vanilagy 3400b3ac12 Add maxLiveSegmentCount HLS option 2026-03-31 17:58:02 +02:00
Vanilagy 340b5eede7 Add support for writing Unix epoch-relative tracks to HLS, add proper cleanup of all Targets obtained by an Output 2026-03-31 15:12:38 +02:00
Vanilagy b06e407d65 Add HLS live mode 2026-03-31 14:13:00 +02:00
Vanilagy 3bcbcc13f0 Add CMAF format and CMAF/init segment support to HLS muxer 2026-03-30 17:06:57 +02:00
Vanilagy 94678dd356 Add support for writing I-frame only tracks, fix track closing race conditions in other muxers 2026-03-27 18:48:27 +01:00
Vanilagy e2e8aaab78 Refactor Target and Writer, add single-file HLS writing mode 2026-03-27 18:07:26 +01:00
Vanilagy b8044cfa07 Add more segmentation tests 2026-03-27 14:27:30 +01:00
Vanilagy 17fac170c1 Add some HLS events, add configurable target duration, add public-API OutputTrack 2026-03-27 13:37:14 +01:00
Vanilagy 5bc1a31b8e Rewrite HLS segmentation algo AGAIN, add a bunch of HLS segmentation tests, add VideoEncoder/AudioEncoder timing refinement logic, fix HLS output spec violations 2026-03-26 16:23:07 +01:00
Vanilagy 157582498f Remove InputTrack.groupId, hide pairing mask, change HLS track merging behavior 2026-03-24 21:54:00 +01:00
Vanilagy 3e87d747e6 Add HLS master playlist generation, add multi-playlistadd output track grouping, add multi-playlist HLS files, add configurable playlist and segment names, add TrackDisposition.primary 2026-03-24 15:53:21 +01:00
Vanilagy c91718cdba Add SourceRef system to keep track of used Sources (fixes #332) 2026-03-20 14:46:12 +01:00
Vanilagy 587e98391e Merge branch 'main' into hls 2026-03-19 16:52:00 +01:00
31d86331ec FLAC: Add appendOnly option for FlaxMuxer, fix FlacDemuxer reading it (#325)
* implement in FlacOutputFormatOptions

* implement in flac-muxer.ts

* Fix demuxer: Handle minimumFrameSize = 0, maxiumFrameSize = 0

* add a test

* Update flac-demuxer.ts

* Update flac.test.ts

* clean up comments for minima and maxima

* Add FlacOutputFormatOptions.appendOnly to docs

---------

Co-authored-by: Vanilagy <[email protected]>
2026-03-19 13:43:28 +00:00
Vanilagy e693765d23 Fix failing test 2026-03-19 12:33:27 +01:00
Vanilagy a9a455e132 Add metadata-based duration retrieval 2026-03-13 17:03:36 +01:00
Vanilagy e8df451bf5 Add support for live HLS streams, add playlist refresh logic, add live input tracks 2026-03-12 15:54:19 +01:00
Vanilagy ff523c01c8 Add HLS reading tests, InputTrack.hasOnlyKeyPackets, faster whole-file reading 2026-03-10 13:32:52 +01:00
Vanilagy 22716b1f83 Merge branch 'main' into hls 2026-03-06 10:59:24 +01:00
6a11a1302c Fix CTS=0 in fragmented fMP4 with multiple tracks (#317)
* Fix CTS=0 in fragmented fMP4 with multiple tracks

When muxing fragmented MP4 with both video and audio tracks,
compositionTimeOffset (CTS) was zero for all video samples, causing
B-frame content to display in decode order instead of presentation
order (visible judder).

Root cause: During finalize(), interleaveSamples(true) triggers
finalizeFragment() via the cross-track keyframe check in
addSampleToTrack. This writes the trun box before processTimestamps
has computed correct decodeTimestamp values, so CTS = PTS - DTS = 0.

Fix: Call processTimestamps() for all tracks at the start of
finalizeFragment(). This is safe because processTimestamps is a no-op
when the timestampProcessingQueue is empty.

Video-only fragmented muxing was unaffected because the single-track
case never triggers the cross-track keyframe check during
interleaveSamples.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* Fix the problem at the actual root

* Oopsie doopsie

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>
Co-authored-by: Vanilagy <[email protected]>
2026-03-06 09:56:53 +00:00
Vanilagy fa4a0b4806 Merge branch 'main' into hls 2026-03-04 21:49:51 +01:00
Vanilagy a15283eaa3 Add @mediabunny/flac-encoder extension, clean up some other code, fix incorrect top-level tsconfig 2026-03-04 21:21:52 +01:00
Vanilagy 365469e64e Merge branch 'main' into hls 2026-03-04 17:33:16 +01:00
Vanilagy c4398fb88c Add @mediabunny/aac-encoder extension package 2026-03-04 17:05:34 +01:00
Vanilagy b0604150c1 Merge branch 'main' into hls 2026-02-26 15:53:46 +01:00
Vanilagy bb4749cd8d Add support for reading/writing non-square pixel video frames (fixes #309) 2026-02-25 17:16:33 +01:00
Vanilagy 68b3ae7155 A BUNCH of HLS (and related) progress
- Add support for fMP4 segments
- Add initInput (supported by ISOBMFF and MPEG-TS)
- Input.isSupported()
- Refactored file size retrieval logic, the file size can now be retrieved alongside the first read.
- Add support for unsized UrlSources
- Add support for multiple trun boxes in a row for the same track (as the spec literally says lol)
- Add support for more M3U8 features
- Fix faulty line reader
- MPEG-TS improvements: support video parameters not in first packet, support better key frame detection, support extension PES packets without PTS
- Fix reorder buffer being 1 element too small
2026-02-20 19:56:20 +01:00
Vanilagy de84d78092 Merge branch 'main' into hls 2026-02-16 15:55:59 +01:00
2876197631 Fix WaveDemuxer reading too far in corrupted ID3 chunk (#301)
* Update read-mp4.test.ts

* Fix the bug

* Delete read-wav.test.ts

* Submit test file

* Small adjustments

---------

Co-authored-by: Vanilagy <[email protected]>
2026-02-16 10:48:07 +00:00
Vanilagy a97200f3f0 Add @mediabunny/ac3 extension package 2026-02-12 18:31:59 +01:00
417c85d8ed feat(codec): add detection support for AC-3, E-AC-3 audio codecs (#275)
* ac3/eac3 detection

* fix tests

* review pass + follow codebase comments style

* Add ac3/eac3 to docs

* WIP mpeg-2

* Set registration_descriptor

* add support for ac3 system b in mpeg-ts

* Update docs with ac3 in .ts support

* fix formatting

* Remove default to fix linter

* Add eac3 to mpeg-ts

* fix formatting

* Fix failing test

* Refactor AC3/EAC3 code a little

---------

Co-authored-by: Vanilagy <[email protected]>
2026-02-11 15:23:12 +01:00
Vanilagy d1fbea3e19 [WIP] Add majority of logic for HLS reading support 2026-01-27 14:45:44 +01:00