Commit Graph
98 Commits
Author SHA1 Message Date
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
Vanilagy 7aa0fa465e Add support for ID3 metadata in ADTS, make MPEG-TS demuxer more resilient 2026-01-27 14:32:16 +01:00
Vanilagy 92454b28f7 Use random_access_indicator for key packet detection, rewrite packet lookup algorithm to use a chunked approach to perform better over the network 2026-01-23 13:16:41 +01:00
Vanilagy e1e32c9505 Up the timeout 2026-01-20 20:12:17 +01:00
Vanilagy 79f19b6717 Fix MPEG-TS demuxer reading entire file in the metadata phase, optimize it a bit, bump patch 2026-01-20 20:08:17 +01:00
Vanilagy 277290abe3 Fix tests and elaborate on point in docs 2026-01-19 14:11:02 +01:00
Vanilagy 53b04619e1 Convert ADTS to AAC in muxers that accept it 2026-01-16 17:27:50 +01:00
Vanilagy e8b27768a9 Add MPEG-TS muxer, fix a demuxer bug, remove Infinity from output format track counts 2026-01-16 16:33:28 +01:00
Vanilagy ae37973878 MPEG-TS demuxer optimizations: faster Annex B segmentation, better NALU iteration 2026-01-16 13:26:58 +01:00
Vanilagy e3ee9d91a9 Add MP3 support to MPEG-TS demuxer 2026-01-16 10:28:00 +01:00
Vanilagy c0f2693cb3 Add HEVC support to MPEG-TS demuxer 2026-01-16 10:05:40 +01:00
Vanilagy 54dfa75a7e Add proper packet duration extraction to MPEG-TS demuxer 2026-01-15 16:33:17 +01:00
Vanilagy 8fea9671ea Fix some demuxer bugs that occurred on files by FFmpeg, fix packet marking logic 2026-01-15 08:51:07 +01:00
Vanilagy 0719a17c85 Add mutex to packet lookup algorithm, fix incorrect next packet retrieval following packet lookup 2026-01-14 21:53:23 +01:00
Vanilagy 045df3b9a5 Make ADTS demuxer spit out ADTS packets instead of AAC, make ADTS muxer accept both AAC and ADTS input 2026-01-14 13:52:46 +01:00
Vanilagy 06ab9c8433 Add support for different TS packet strides and offsets, add proper input format detection, fix error messages, add packet lookup algorithm with no file size known 2026-01-14 13:16:40 +01:00
Vanilagy 888441232d Implement the bulk of the MPEG-TS demuxer, add a bunch of tests, and a few other things 2026-01-14 12:05:39 +01:00
Vanilagy c86af052f5 Add test for Annex B to length-prefixed conversion 2025-12-19 16:04:27 +01:00
Vanilagy 228721d68f Add VideoSampleColorSpace 2025-12-16 18:47:50 +01:00
Vanilagy abe6185ddd Fix test? 2025-11-13 11:02:36 +01:00
Vanilagy 217b383f12 Add read/write support for track disposition information 2025-11-13 11:00:42 +01:00
Vanilagy d708df9a2c Add mdta MP4 metadata tests 2025-09-26 10:14:52 +02:00
Vanilagy e7c7a82fe3 Fix test 2025-09-26 10:06:13 +02:00
6aee4e6a6a Fix WAV files with embedded ID3 metadata returning empty tags (#110)
* Read ID3v2 tags from WAV file

* remove js import

Co-authored-by: David P. <[email protected]>

* revert slicing in wave-demuxer.ts and add id3.ts for further sharing

* Add `writeId3Tag` to the `WavOutputFormat` constructor options

* add more context in private and public APIs that it's non-standard

* compare actual values in the test with real file

* remove unnecesarry double slice requesting

* trim test audio file (i tried my best to preserve ID3, including artwork)

* Couple of code cleanups

* const -> using

* Fix linting errors

---------

Co-authored-by: David P. <[email protected]>
2025-09-22 14:06:06 +02:00
Vanilagy 608c769a7e Add explicit disposability to Inputs (#126) 2025-09-21 20:18:59 +02:00
Vanilagy a3f4f7f4f7 Allow all Matroska AttachedFiles to be read & written via metadata tags 2025-09-19 20:12:29 +02:00
d426d36386 FLAC container support (#95)
* add a test

* recognize as input format

* scaffold flac demuxer

* implement getting metadata

* Implement mime type

* read all metadata + deduplicate stubs

* Read first packet

* copyright headers

* read the first packet

* Get entire first packet, work on advancing

* iterate over all samples

* testable with bun

* stub out metadata support

* parse descriptive metadata

* All in 1 file

seems more appropriate to the philosophy

* some parameters are not needed anymore all within 1 class

* skip over bytes we are sure are not the syncword

* run prettier

* timestamp is determined based on passed blocks, not maximumBlockSize

* no binary search needed!

* simplifications

* Finish demuxer reading sequentially

* more tests + add a file with a seektable

* don't throw if (this.audioInfo.minimumBlockSize !== this.audioInfo.maximumBlockSize

* Add docs

* Update format compatibility table

* Simplification

* confirm conversion is working

* Finish

* Resolve TODO comment

* Support images (read-only)

* Returning description as Uint8Array

* Cleanup of demuxer

* Misc renames

* Object on same line

* Resolve first batch of comments

* Throw errors on corrupt blocks, correctly use requestSlice()

* Fix description field

* Explain why last frame is a bit shorter

* Add FLAC to README

* Put track backings below demuxer

* convert to methods

* Reorder container checking

* getBlockSize() -> readBlockSize()

* bitStream -> bitstream

* better naming for bytes

* use .skip()

* Don't return blockSize twice in readFlacFrameHeader

* Use enum + switch to distinguish Flac block types

* Use else-if

* Use else-if

* Compressed switch statement

* readCodedNumber

* Update flac-misc.ts

* We don't need the bits variable at all

* reorder functions in flac-demuxer

* Handle gracefully not being able to load another sample

* Update flac-demuxer.ts

* blockingbit null

* use async instead of promise.resolve

* use binary search

* Replace recursion with while loop

* Add mutex to getPacket()

* Load more data not in getPacketAtIndex, but outside

* Apply suggestion from @Vanilagy

Co-authored-by: David P. <[email protected]>

* computeDuration() reads last packet

* Update flac-demuxer.ts

* share vorbis comment reading logic

* reuse vorbis comment writing logic, set vendor always to "Mediabunny"

* flush after writign

* Use FileSlice.tempFromBytes

* assert !== null

* fixing nitpicks

* apply suggestions

* fix ogg

* We are now muxing images

* apply suggestion

* Update src/flac/flac-muxer.ts

Co-authored-by: David P. <[email protected]>

* apply suggestion

* readSampleRate()

* seek outside writeHeader()

* mention vorbis metadata +  add to metadatatags comment

* should be able to -> can

* Add test in metadata tags

* Add test for packets being byte identical after remuxing

* compare to null

* no casting to uint8array

* make test pass

* Update flac-muxer.ts

* Call validateAudioChunkMetadata() and validateAndNormalizeTimestamp()

* `onFrame` option

* emit frames using onFrame

* Run prettier over files

* Fix FLAC PICTURE block logic, small other changes

* Update docs

* Remove .only modifier

* fix remuxing and add test

* Don't throw error if parsing fails in header, since hitting a syncword might just be coincidential

* Fix remaining type errors

---------

Co-authored-by: David P. <[email protected]>
2025-09-18 21:05:09 +02:00
Vanilagy dcd99f8930 Add metadata tag support to Conversion API 2025-09-05 23:34:24 +02:00
Vanilagy bd99d8f28f Add metadata tests, fix a few bugs 2025-09-05 21:42:26 +02:00
Jonny BurgerandGitHub f13a2e6732 Merge pull request #86 from JonnyBurger/url-source-allow-reading-small-files
Do not make UrlSource fail if the size of the file is smaller than 512kb (+ add a Vitest browser mode test)
2025-09-03 18:13:42 +02:00