Files
mediabunny/src/index.ts
T
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

203 lines
3.7 KiB
TypeScript

/*!
* Copyright (c) 2025-present, Vanilagy and contributors
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
/// <reference types="dom-mediacapture-transform" preserve="true" />
/// <reference types="dom-webcodecs" preserve="true" />
export {
Output,
OutputOptions,
BaseTrackMetadata,
VideoTrackMetadata,
AudioTrackMetadata,
SubtitleTrackMetadata,
} from './output';
export {
OutputFormat,
AdtsOutputFormat,
AdtsOutputFormatOptions,
FlacOutputFormat,
FlacOutputFormatOptions,
IsobmffOutputFormat,
IsobmffOutputFormatOptions,
MkvOutputFormat,
MkvOutputFormatOptions,
MovOutputFormat,
Mp3OutputFormat,
Mp3OutputFormatOptions,
Mp4OutputFormat,
OggOutputFormat,
OggOutputFormatOptions,
WavOutputFormat,
WavOutputFormatOptions,
WebMOutputFormat,
WebMOutputFormatOptions,
InclusiveIntegerRange,
TrackCountLimits,
} from './output-format';
export {
MediaSource,
VideoSource,
AudioSource,
SubtitleSource,
AudioBufferSource,
AudioSampleSource,
CanvasSource,
EncodedAudioPacketSource,
EncodedVideoPacketSource,
MediaStreamAudioTrackSource,
MediaStreamVideoTrackSource,
TextSubtitleSource,
VideoSampleSource,
} from './media-source';
export {
MediaCodec,
VideoCodec,
AudioCodec,
SubtitleCodec,
VIDEO_CODECS,
AUDIO_CODECS,
PCM_AUDIO_CODECS,
NON_PCM_AUDIO_CODECS,
SUBTITLE_CODECS,
} from './codec';
export {
VideoEncodingConfig,
VideoEncodingAdditionalOptions,
AudioEncodingConfig,
AudioEncodingAdditionalOptions,
canEncode,
canEncodeVideo,
canEncodeAudio,
canEncodeSubtitles,
getEncodableCodecs,
getEncodableVideoCodecs,
getEncodableAudioCodecs,
getEncodableSubtitleCodecs,
getFirstEncodableVideoCodec,
getFirstEncodableAudioCodec,
getFirstEncodableSubtitleCodec,
Quality,
QUALITY_VERY_LOW,
QUALITY_LOW,
QUALITY_MEDIUM,
QUALITY_HIGH,
QUALITY_VERY_HIGH,
} from './encode';
export {
Target,
BufferTarget,
NullTarget,
StreamTarget,
StreamTargetOptions,
StreamTargetChunk,
} from './target';
export {
AnyIterable,
MaybePromise,
Rotation,
SetRequired,
} from './misc';
export {
TrackType,
ALL_TRACK_TYPES,
} from './output';
export {
Source,
BlobSource,
BlobSourceOptions,
BufferSource,
FilePathSource,
FilePathSourceOptions,
StreamSource,
StreamSourceOptions,
ReadableStreamSource,
ReadableStreamSourceOptions,
UrlSource,
UrlSourceOptions,
} from './source';
export {
InputFormat,
AdtsInputFormat,
IsobmffInputFormat,
MatroskaInputFormat,
Mp3InputFormat,
Mp4InputFormat,
OggInputFormat,
QuickTimeInputFormat,
WaveInputFormat,
WebMInputFormat,
FlacInputFormat,
ALL_FORMATS,
ADTS,
MATROSKA,
MP3,
MP4,
OGG,
QTFF,
WAVE,
WEBM,
FLAC,
} from './input-format';
export {
Input,
InputOptions,
} from './input';
export {
InputTrack,
InputVideoTrack,
InputAudioTrack,
PacketStats,
} from './input-track';
export {
EncodedPacket,
PacketType,
} from './packet';
export {
AudioSample,
AudioSampleInit,
AudioSampleCopyToOptions,
VideoSample,
VideoSampleInit,
CropRectangle,
} from './sample';
export {
AudioBufferSink,
AudioSampleSink,
BaseMediaSampleSink,
CanvasSink,
CanvasSinkOptions,
EncodedPacketSink,
PacketRetrievalOptions,
VideoSampleSink,
WrappedAudioBuffer,
WrappedCanvas,
} from './media-sink';
export {
Conversion,
ConversionOptions,
ConversionVideoOptions,
ConversionAudioOptions,
DiscardedTrack,
} from './conversion';
export {
CustomVideoDecoder,
CustomVideoEncoder,
CustomAudioDecoder,
CustomAudioEncoder,
registerDecoder,
registerEncoder,
} from './custom-coder';
export {
MetadataTags,
AttachedImage,
RichImageData,
} from './tags';
// 🐡🦔