🎥 Make videos programmatically with React
bit depth
Jonny Burger48f9c8de2052
diff --git a/packages/media-parser/src/boxes/webm/segments.ts b/packages/media-parser/src/boxes/webm/segments.tsindex fb147ff54e..d355d2b369 100644--- a/packages/media-parser/src/boxes/webm/segments.ts+++ b/packages/media-parser/src/boxes/webm/segments.ts@@ -10,13 +10,11 @@ import {matroskaElements} from './segments/all-segments';import {type MainSegment} from './segments/main';import {expectChildren} from './segments/parse-children';import type {- AlphaModeSegment,AudioSegment,BitDepthSegment,BlockAdditionsSegment,BlockElement,BlockGroupSegment,- ChannelsSegment,ClusterSegment,CodecPrivateSegment,ColorSegment,@@ -25,11 +23,9 @@ import type {DisplayHeightSegment,DisplayWidthSegment,FlagLacingSegment,- InterlacedSegment,LanguageSegment,MaxBlockAdditionId,ReferenceBlockSegment,- SamplingFrequencySegment,SimpleBlockOrBlockSegment,TagSegment,TagsSegment,@@ -40,13 +36,11 @@ import type {VideoSegment,} from './segments/track-entry';import {- parseAlphaModeSegment,parseAudioSegment,parseBitDepthSegment,parseBlockAdditionsSegment,parseBlockElementSegment,parseBlockGroupSegment,- parseChannelsSegment,parseCodecPrivateSegment,parseColorSegment,parseDefaultDurationSegment,@@ -54,11 +48,9 @@ import {parseDisplayHeightSegment,parseDisplayWidthSegment,parseFlagLacing,- parseInterlacedSegment,parseLanguageSegment,parseMaxBlockAdditionId,parseReferenceBlockSegment,- parseSamplingFrequencySegment,parseSimpleBlockOrBlockSegment,parseTagSegment,parseTagsSegment,@@ -83,10 +75,8 @@ export type MatroskaSegment =| VideoSegment| DisplayWidthSegment| DisplayHeightSegment- | AlphaModeSegment| MaxBlockAdditionId| ColorSegment- | InterlacedSegment| CodecPrivateSegment| DefaultFlagSegment| TagsSegment@@ -97,8 +87,6 @@ export type MatroskaSegment =| BlockGroupSegment| BlockElement| AudioSegment- | SamplingFrequencySegment- | ChannelsSegment| BitDepthSegment| ReferenceBlockSegment| BlockAdditionsSegment@@ -192,14 +180,6 @@ const parseSegment = async ({return parseDisplayHeightSegment(iterator, length);}- if (segmentId === '0x9a') {- return parseInterlacedSegment(iterator, length);- }-- if (segmentId === '0x53c0') {- return parseAlphaModeSegment(iterator, length);- }-if (segmentId === '0x63a2') {return parseCodecPrivateSegment(iterator, length);}@@ -216,14 +196,6 @@ const parseSegment = async ({return parseTagSegment(iterator, length);}- if (segmentId === matroskaElements.SamplingFrequency) {- return parseSamplingFrequencySegment(iterator, length);- }-- if (segmentId === matroskaElements.Channels) {- return parseChannelsSegment(iterator, length);- }-if (segmentId === matroskaElements.BitDepth) {return parseBitDepthSegment(iterator, length);}diff --git a/packages/media-parser/src/boxes/webm/segments/all-segments.ts b/packages/media-parser/src/boxes/webm/segments/all-segments.tsindex c128337df2..a10938e790 100644--- a/packages/media-parser/src/boxes/webm/segments/all-segments.ts+++ b/packages/media-parser/src/boxes/webm/segments/all-segments.ts@@ -493,6 +493,26 @@ export const titleType = {type: 'string',} as const satisfies Ebml;+export const samplingFrequency = {+ name: 'SamplingFrequency',+ type: 'float',+} as const satisfies Ebml;++export const channels = {+ name: 'Channels',+ type: 'uint',+} as const satisfies Ebml;++export const alphaMode = {+ name: 'AlphaMode',+ type: 'uint',+} as const satisfies Ebml;++export const interlaced = {+ name: 'FlagInterlaced',+ type: 'uint',+} as const satisfies Ebml;+export type CodecIdSegment = EbmlParsed<typeof codecID>;export type TrackTypeSegment = EbmlParsed<typeof trackType>;export type WidthSegment = EbmlParsed<typeof widthType>;@@ -596,6 +616,10 @@ export const ebmlMap = {[matroskaElements.TimestampScale]: timestampScale,[matroskaElements.Info]: infoType,[matroskaElements.Title]: titleType,+ [matroskaElements.SamplingFrequency]: samplingFrequency,+ [matroskaElements.Channels]: channels,+ [matroskaElements.AlphaMode]: alphaMode,+ [matroskaElements.FlagInterlaced]: interlaced,} as const satisfies Partial<Record<MatroskaElement, Ebml>>;export type PossibleEbml = Prettify<diff --git a/packages/media-parser/src/boxes/webm/segments/track-entry.ts b/packages/media-parser/src/boxes/webm/segments/track-entry.tsindex 31efb0bf34..675da9a7d5 100644--- a/packages/media-parser/src/boxes/webm/segments/track-entry.ts+++ b/packages/media-parser/src/boxes/webm/segments/track-entry.ts@@ -258,27 +258,6 @@ export const parseDisplayHeightSegment = (};};-export type AlphaModeSegment = {- type: 'alpha-mode-segment';- alphaMode: number;-};--export const parseAlphaModeSegment = (- iterator: BufferIterator,- length: number,-): AlphaModeSegment => {- if (length !== 1) {- throw new Error('Expected alpha mode segment to be 1 byte');- }-- const alphaMode = iterator.getUint8();-- return {- type: 'alpha-mode-segment',- alphaMode,- };-};-export type MaxBlockAdditionId = {type: 'max-block-addition-id-segment';maxBlockAdditionId: number;@@ -317,29 +296,6 @@ export const parseColorSegment = (};};-export type InterlacedSegment = {- type: 'interlaced-segment';- interlaced: boolean;-};--export const parseInterlacedSegment = (- iterator: BufferIterator,- length: number,-): InterlacedSegment => {- if (length !== 1) {- throw new Error(- 'Expected interlaced segment to be 1 byte, but is ' + length,- );- }-- const interlaced = iterator.getUint8();-- return {- type: 'interlaced-segment',- interlaced: Boolean(interlaced),- };-};-export type CodecPrivateSegment = {type: 'codec-private-segment';codecPrivateData: Uint8Array;@@ -665,57 +621,6 @@ export const parseBlockElementSegment = (};};-export type SamplingFrequencySegment = {- type: 'sampling-frequency-segment';- samplingFrequency: number;-};--export const parseSamplingFrequencySegment = (- iterator: BufferIterator,- length: number,-): SamplingFrequencySegment => {- if (length === 4) {- return {- type: 'sampling-frequency-segment',- samplingFrequency: iterator.getFloat32(),- };- }-- if (length === 8) {- return {- type: 'sampling-frequency-segment',- samplingFrequency: iterator.getFloat64(),- };- }-- throw new Error(- `Expected length of sampling frequency segment to be 4 or 8, got ${length}`,- );-};--export type ChannelsSegment = {- type: 'channels-segment';- channels: number;-};--export const parseChannelsSegment = (- iterator: BufferIterator,- length: number,-): ChannelsSegment => {- if (length !== 1) {- throw new Error(- `Expected length of channels segment to be 1, got ${length}`,- );- }-- const channels = iterator.getUint8();-- return {- type: 'channels-segment',- channels,- };-};-export type BitDepthSegment = {type: 'bit-depth-segment';bitDepth: number;diff --git a/packages/media-parser/src/traversal.ts b/packages/media-parser/src/traversal.tsindex 0285f93760..5bab913d14 100644--- a/packages/media-parser/src/traversal.ts+++ b/packages/media-parser/src/traversal.ts@@ -309,17 +309,14 @@ export const getSampleRate = (track: TrackEntrySegment): number | null => {}const samplingFrequency = audioSegment.children.find(- (b) => b.type === 'sampling-frequency-segment',+ (b) => b.type === 'SamplingFrequency',);- if (- !samplingFrequency ||- samplingFrequency.type !== 'sampling-frequency-segment'- ) {+ if (!samplingFrequency || samplingFrequency.type !== 'SamplingFrequency') {return null;}- return samplingFrequency.samplingFrequency;+ return samplingFrequency.value;};export const getNumberOfChannels = (track: TrackEntrySegment): number => {@@ -328,15 +325,13 @@ export const getNumberOfChannels = (track: TrackEntrySegment): number => {throw new Error('Could not find audio segment');}- const channels = audioSegment.children.find(- (b) => b.type === 'channels-segment',- );+ const channels = audioSegment.children.find((b) => b.type === 'Channels');- if (!channels || channels.type !== 'channels-segment') {+ if (!channels || channels.type !== 'Channels') {return 1;}- return channels.channels;+ return channels.value;};export const getBitDepth = (track: TrackEntrySegment): number | null => {