@remotion/webcodecs 4.0.341 → 4.0.345

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,6 +26,16 @@ const internalCreateAudioDecoder = async ({ onFrame, onError, controller, config
26
26
  onError,
27
27
  });
28
28
  }
29
+ if (config.codec === 'pcm-s24') {
30
+ return (0, get_wave_audio_decoder_1.getWaveAudioDecoder)({
31
+ onFrame,
32
+ config,
33
+ sampleFormat: 's24',
34
+ logLevel,
35
+ ioSynchronizer,
36
+ onError,
37
+ });
38
+ }
29
39
  const audioDecoder = new AudioDecoder({
30
40
  async output(frame) {
31
41
  try {
@@ -4185,29 +4185,26 @@ var getBytesPerSample = (sampleFormat) => {
4185
4185
  if (sampleFormat === "s16") {
4186
4186
  return 2;
4187
4187
  }
4188
- if (sampleFormat === "s32") {
4188
+ if (sampleFormat === "s24") {
4189
4189
  return 4;
4190
4190
  }
4191
- if (sampleFormat === "f32") {
4192
- return 4;
4193
- }
4194
- if (sampleFormat === "u8") {
4195
- return 1;
4196
- }
4197
- if (sampleFormat === "f32-planar") {
4198
- return 4;
4199
- }
4200
- if (sampleFormat === "s16-planar") {
4201
- return 2;
4202
- }
4203
- if (sampleFormat === "s32-planar") {
4204
- return 4;
4205
- }
4206
- if (sampleFormat === "u8-planar") {
4207
- return 1;
4208
- }
4209
4191
  throw new Error(`Unsupported sample format: ${sampleFormat}`);
4210
4192
  };
4193
+ function uint8_24le_to_uint32(u8) {
4194
+ if (u8.length % 3 !== 0) {
4195
+ throw new Error("Input length must be a multiple of 3");
4196
+ }
4197
+ const count = u8.length / 3;
4198
+ const out = new Uint32Array(count);
4199
+ let j = 0;
4200
+ for (let i = 0;i < count; i++) {
4201
+ const b0 = u8[j++];
4202
+ const b1 = u8[j++];
4203
+ const b2 = u8[j++];
4204
+ out[i] = (b0 | b1 << 8 | b2 << 16) << 8;
4205
+ }
4206
+ return out;
4207
+ }
4211
4208
  var getAudioData = (audioSample) => {
4212
4209
  if (audioSample instanceof EncodedAudioChunk) {
4213
4210
  const data = new Uint8Array(audioSample.byteLength);
@@ -4225,12 +4222,14 @@ var getWaveAudioDecoder = ({
4225
4222
  }) => {
4226
4223
  const processSample = async (audioSample) => {
4227
4224
  const bytesPerSample = getBytesPerSample(sampleFormat);
4228
- const data = getAudioData(audioSample);
4225
+ const rawData = getAudioData(audioSample);
4226
+ const data = sampleFormat === "s24" && rawData instanceof Uint8Array ? uint8_24le_to_uint32(rawData) : rawData;
4227
+ const numberOfFrames = data.byteLength / bytesPerSample / config.numberOfChannels;
4229
4228
  const audioData = new AudioData({
4230
4229
  data,
4231
- format: sampleFormat,
4230
+ format: sampleFormat === "s16" ? "s16" : "s32",
4232
4231
  numberOfChannels: config.numberOfChannels,
4233
- numberOfFrames: data.byteLength / bytesPerSample / config.numberOfChannels,
4232
+ numberOfFrames,
4234
4233
  sampleRate: config.sampleRate,
4235
4234
  timestamp: audioSample.timestamp
4236
4235
  });
@@ -4321,6 +4320,16 @@ var internalCreateAudioDecoder = async ({
4321
4320
  onError
4322
4321
  });
4323
4322
  }
4323
+ if (config.codec === "pcm-s24") {
4324
+ return getWaveAudioDecoder({
4325
+ onFrame,
4326
+ config,
4327
+ sampleFormat: "s24",
4328
+ logLevel,
4329
+ ioSynchronizer,
4330
+ onError
4331
+ });
4332
+ }
4324
4333
  const audioDecoder = new AudioDecoder({
4325
4334
  async output(frame) {
4326
4335
  try {
@@ -2,7 +2,7 @@ import type { MediaParserLogLevel } from '@remotion/media-parser';
2
2
  import type { CreateAudioDecoderInit, WebCodecsAudioDecoder } from './create-audio-decoder';
3
3
  import type { IoSynchronizer } from './io-manager/io-synchronizer';
4
4
  export declare const getWaveAudioDecoder: ({ onFrame, config, sampleFormat, ioSynchronizer, onError, }: Pick<CreateAudioDecoderInit, "onFrame" | "config"> & {
5
- sampleFormat: AudioSampleFormat;
5
+ sampleFormat: "s16" | "s24";
6
6
  logLevel: MediaParserLogLevel;
7
7
  ioSynchronizer: IoSynchronizer;
8
8
  onError: (error: Error) => void;
@@ -5,29 +5,26 @@ const getBytesPerSample = (sampleFormat) => {
5
5
  if (sampleFormat === 's16') {
6
6
  return 2;
7
7
  }
8
- if (sampleFormat === 's32') {
8
+ if (sampleFormat === 's24') {
9
9
  return 4;
10
10
  }
11
- if (sampleFormat === 'f32') {
12
- return 4;
13
- }
14
- if (sampleFormat === 'u8') {
15
- return 1;
16
- }
17
- if (sampleFormat === 'f32-planar') {
18
- return 4;
19
- }
20
- if (sampleFormat === 's16-planar') {
21
- return 2;
22
- }
23
- if (sampleFormat === 's32-planar') {
24
- return 4;
25
- }
26
- if (sampleFormat === 'u8-planar') {
27
- return 1;
28
- }
29
11
  throw new Error(`Unsupported sample format: ${sampleFormat}`);
30
12
  };
13
+ function uint8_24le_to_uint32(u8) {
14
+ if (u8.length % 3 !== 0) {
15
+ throw new Error('Input length must be a multiple of 3');
16
+ }
17
+ const count = u8.length / 3;
18
+ const out = new Uint32Array(count);
19
+ let j = 0;
20
+ for (let i = 0; i < count; i++) {
21
+ const b0 = u8[j++];
22
+ const b1 = u8[j++];
23
+ const b2 = u8[j++];
24
+ out[i] = (b0 | (b1 << 8) | (b2 << 16)) << 8;
25
+ }
26
+ return out;
27
+ }
31
28
  const getAudioData = (audioSample) => {
32
29
  if (audioSample instanceof EncodedAudioChunk) {
33
30
  const data = new Uint8Array(audioSample.byteLength);
@@ -39,12 +36,16 @@ const getAudioData = (audioSample) => {
39
36
  const getWaveAudioDecoder = ({ onFrame, config, sampleFormat, ioSynchronizer, onError, }) => {
40
37
  const processSample = async (audioSample) => {
41
38
  const bytesPerSample = getBytesPerSample(sampleFormat);
42
- const data = getAudioData(audioSample);
39
+ const rawData = getAudioData(audioSample);
40
+ const data = sampleFormat === 's24' && rawData instanceof Uint8Array
41
+ ? uint8_24le_to_uint32(rawData)
42
+ : rawData;
43
+ const numberOfFrames = data.byteLength / bytesPerSample / config.numberOfChannels;
43
44
  const audioData = new AudioData({
44
45
  data,
45
- format: sampleFormat,
46
+ format: sampleFormat === 's16' ? 's16' : 's32',
46
47
  numberOfChannels: config.numberOfChannels,
47
- numberOfFrames: data.byteLength / bytesPerSample / config.numberOfChannels,
48
+ numberOfFrames,
48
49
  sampleRate: config.sampleRate,
49
50
  timestamp: audioSample.timestamp,
50
51
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remotion/webcodecs",
3
- "version": "4.0.341",
3
+ "version": "4.0.345",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "module": "dist/esm/index.mjs",
@@ -19,18 +19,18 @@
19
19
  "author": "Jonny Burger <jonny@remotion.dev>",
20
20
  "license": "Remotion License (See https://remotion.dev/docs/webcodecs#license)",
21
21
  "dependencies": {
22
- "@remotion/media-parser": "4.0.341",
23
- "@remotion/licensing": "4.0.341"
22
+ "@remotion/media-parser": "4.0.345",
23
+ "@remotion/licensing": "4.0.345"
24
24
  },
25
25
  "peerDependencies": {},
26
26
  "devDependencies": {
27
27
  "@types/dom-webcodecs": "0.1.11",
28
28
  "playwright": "1.51.1",
29
- "vite": "5.4.19",
29
+ "vite": "5.4.20",
30
30
  "@playwright/test": "1.51.1",
31
31
  "eslint": "9.19.0",
32
- "@remotion/example-videos": "4.0.341",
33
- "@remotion/eslint-config-internal": "4.0.341"
32
+ "@remotion/eslint-config-internal": "4.0.345",
33
+ "@remotion/example-videos": "4.0.345"
34
34
  },
35
35
  "keywords": [],
36
36
  "publishConfig": {