-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4050e52
commit 5bd86d6
Showing
9 changed files
with
158 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import type {BufferIterator} from '../../buffer-iterator'; | ||
import type {RiffBox} from './riff-box'; | ||
|
||
export const parseFmtBox = ({ | ||
iterator, | ||
boxes, | ||
size, | ||
}: { | ||
iterator: BufferIterator; | ||
boxes: RiffBox[]; | ||
size: number; | ||
}): RiffBox => { | ||
const offset = iterator.counter.getOffset(); | ||
const header = boxes.find((b) => b.type === 'riff-header'); | ||
if (!header) { | ||
throw new Error('Expected RIFF header'); | ||
} | ||
|
||
if (header.fileType !== 'WAVE') { | ||
throw new Error('Only supporting WAVE type'); | ||
} | ||
|
||
const wFormatTag = iterator.getUint16Le(); | ||
if (wFormatTag !== 1) { | ||
throw new Error('Expected wFormatTag to be 1, only supporting this'); | ||
} | ||
|
||
const numberOfChannels = iterator.getUint16Le(); | ||
const sampleRate = iterator.getUint32Le(); | ||
const byteRate = iterator.getUint32Le(); | ||
const blockAlign = iterator.getUint16Le(); | ||
const bitsPerSample = iterator.getUint16Le(); | ||
|
||
iterator.discard(size - (iterator.counter.getOffset() - offset)); | ||
|
||
return { | ||
type: 'wave-format-box', | ||
formatTag: wFormatTag, | ||
numberOfChannels, | ||
sampleRate, | ||
blockAlign, | ||
byteRate, | ||
bitsPerSample, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type {BufferIterator} from '../../buffer-iterator'; | ||
import {parseFmtBox} from './parse-fmt-box'; | ||
import type {RiffBox, RiffRegularBox} from './riff-box'; | ||
|
||
export const parseRiffBox = ({ | ||
iterator, | ||
size, | ||
id, | ||
boxes, | ||
}: { | ||
iterator: BufferIterator; | ||
size: number; | ||
id: string; | ||
boxes: RiffBox[]; | ||
}): RiffBox => { | ||
if (id === 'fmt') { | ||
return parseFmtBox({iterator, boxes, size}); | ||
} | ||
|
||
iterator.discard(size); | ||
|
||
const box: RiffRegularBox = { | ||
type: 'riff-box', | ||
size, | ||
id, | ||
}; | ||
|
||
return box; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {exampleVideos} from '@remotion/example-videos'; | ||
import {expect, test} from 'bun:test'; | ||
import {parseMedia} from '../parse-media'; | ||
import {nodeReader} from '../readers/from-node'; | ||
|
||
test('AVI file', async () => { | ||
const {boxes} = await parseMedia({ | ||
src: exampleVideos.avi, | ||
reader: nodeReader, | ||
fields: { | ||
boxes: true, | ||
}, | ||
}); | ||
expect(boxes).toEqual([ | ||
{ | ||
fileSize: 742470, | ||
fileType: 'AVI', | ||
type: 'riff-header', | ||
}, | ||
{ | ||
id: 'LIST', | ||
size: 8894, | ||
type: 'riff-box', | ||
}, | ||
{ | ||
id: 'LIST', | ||
size: 26, | ||
type: 'riff-box', | ||
}, | ||
{ | ||
id: 'JUNK', | ||
size: 1016, | ||
type: 'riff-box', | ||
}, | ||
{ | ||
id: 'LIST', | ||
size: 695114, | ||
type: 'riff-box', | ||
}, | ||
{ | ||
id: 'idx1', | ||
size: 37376, | ||
type: 'riff-box', | ||
}, | ||
]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters