@remotion/media-utils 4.0.457 → 4.0.459

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.
@@ -221,7 +221,7 @@ var fn = async (src, options) => {
221
221
  const audioContext = new AudioContext({
222
222
  sampleRate: options?.sampleRate ?? 48000
223
223
  });
224
- const response = await fetchWithCorsCatch(src);
224
+ const response = await fetchWithCorsCatch(src, options?.requestInit);
225
225
  if (!response.ok) {
226
226
  throw new Error(`Failed to fetch audio data from ${src}: ${response.status} ${response.statusText}`);
227
227
  }
@@ -555,7 +555,7 @@ var getWaveformPortion = ({
555
555
  // src/use-audio-data.ts
556
556
  import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
557
557
  import { cancelRender, useDelayRender } from "remotion";
558
- var useAudioData = (src) => {
558
+ var useAudioData = (src, options) => {
559
559
  if (!src) {
560
560
  throw new TypeError("useAudioData requires a 'src' parameter");
561
561
  }
@@ -569,10 +569,12 @@ var useAudioData = (src) => {
569
569
  }, []);
570
570
  const [metadata, setMetadata] = useState(null);
571
571
  const { delayRender, continueRender } = useDelayRender();
572
+ const sampleRate = options?.sampleRate;
573
+ const [initialRequestInit] = useState(options?.requestInit);
572
574
  const fetchMetadata = useCallback(async () => {
573
575
  const handle = delayRender(`Waiting for audio metadata with src="${src}" to be loaded`);
574
576
  try {
575
- const data = await getAudioData(src);
577
+ const data = await getAudioData(src, sampleRate === undefined && initialRequestInit === undefined ? undefined : { sampleRate, requestInit: initialRequestInit });
576
578
  if (mountState.current.isMounted) {
577
579
  setMetadata(data);
578
580
  }
@@ -580,7 +582,7 @@ var useAudioData = (src) => {
580
582
  cancelRender(err);
581
583
  }
582
584
  continueRender(handle);
583
- }, [src, delayRender, continueRender]);
585
+ }, [src, sampleRate, initialRequestInit, delayRender, continueRender]);
584
586
  useLayoutEffect(() => {
585
587
  fetchMetadata();
586
588
  }, [fetchMetadata]);
@@ -679,13 +681,15 @@ var useWindowedAudioData = ({
679
681
  frame,
680
682
  fps,
681
683
  windowInSeconds,
682
- channelIndex = 0
684
+ channelIndex = 0,
685
+ requestInit
683
686
  }) => {
684
687
  const isMounted = useRef2(true);
685
688
  const [audioUtils, setAudioUtils] = useState2(null);
686
689
  const [waveFormMap, setWaveformMap] = useState2({});
687
690
  const requests = useRef2({});
688
691
  const [initialWindowInSeconds] = useState2(windowInSeconds);
692
+ const [initialRequestInit] = useState2(requestInit);
689
693
  if (windowInSeconds !== initialWindowInSeconds) {
690
694
  throw new Error("windowInSeconds cannot be changed dynamically");
691
695
  }
@@ -714,7 +718,7 @@ var useWindowedAudioData = ({
714
718
  signal.addEventListener("abort", cont, { once: true });
715
719
  const input = new Input({
716
720
  formats: ALL_FORMATS,
717
- source: new UrlSource(src)
721
+ source: new UrlSource(src, initialRequestInit ? { requestInit: initialRequestInit } : undefined)
718
722
  });
719
723
  const onAbort = () => {
720
724
  input.dispose();
@@ -766,7 +770,7 @@ var useWindowedAudioData = ({
766
770
  signal.removeEventListener("abort", cont);
767
771
  signal.removeEventListener("abort", onAbort);
768
772
  }
769
- }, [src, delayRender, continueRender, channelIndex]);
773
+ }, [src, delayRender, continueRender, channelIndex, initialRequestInit]);
770
774
  useLayoutEffect2(() => {
771
775
  const controller = new AbortController;
772
776
  fetchMetadata(controller.signal);
@@ -1,6 +1,7 @@
1
1
  import type { MediaUtilsAudioData } from './types';
2
2
  type Options = {
3
3
  sampleRate?: number;
4
+ requestInit?: RequestInit;
4
5
  };
5
6
  export declare const getAudioData: (src: string, options?: Options | undefined) => Promise<MediaUtilsAudioData>;
6
7
  export {};
@@ -17,7 +17,7 @@ const fn = async (src, options) => {
17
17
  const audioContext = new AudioContext({
18
18
  sampleRate: (_a = options === null || options === void 0 ? void 0 : options.sampleRate) !== null && _a !== void 0 ? _a : 48000,
19
19
  });
20
- const response = await (0, fetch_with_cors_catch_1.fetchWithCorsCatch)(src);
20
+ const response = await (0, fetch_with_cors_catch_1.fetchWithCorsCatch)(src, options === null || options === void 0 ? void 0 : options.requestInit);
21
21
  if (!response.ok) {
22
22
  throw new Error(`Failed to fetch audio data from ${src}: ${response.status} ${response.statusText}`);
23
23
  }
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export { getVideoMetadata } from './get-video-metadata';
7
7
  export { getWaveformPortion } from './get-waveform-portion';
8
8
  export * from './types';
9
9
  export type { AudioData, MediaUtilsAudioData, VideoMetadata as VideoData, } from './types';
10
- export { useAudioData } from './use-audio-data';
10
+ export { UseAudioDataOptions, useAudioData } from './use-audio-data';
11
11
  export { UseWindowedAudioDataOptions, UseWindowedAudioDataReturnValue, useWindowedAudioData, } from './use-windowed-audio-data';
12
12
  export { VisualizeAudioOptions, visualizeAudio } from './visualize-audio';
13
13
  export { VisualizeAudioWaveformOptions, visualizeAudioWaveform, } from './visualize-audio-waveform';
@@ -0,0 +1 @@
1
+ export declare const serializeRequestInit: (requestInit: RequestInit | undefined) => string | null;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serializeRequestInit = void 0;
4
+ const normalizeHeaders = (headers) => {
5
+ if (!headers) {
6
+ return null;
7
+ }
8
+ if (typeof Headers !== 'undefined' && headers instanceof Headers) {
9
+ return Array.from(headers.entries()).sort(([a], [b]) => a.localeCompare(b));
10
+ }
11
+ if (Array.isArray(headers)) {
12
+ return [...headers].sort(([a], [b]) => a.localeCompare(b));
13
+ }
14
+ return Object.entries(headers).sort(([a], [b]) => a.localeCompare(b));
15
+ };
16
+ const serializeRequestInit = (requestInit) => {
17
+ if (!requestInit) {
18
+ return null;
19
+ }
20
+ const { headers, signal, ...rest } = requestInit;
21
+ return JSON.stringify({
22
+ ...rest,
23
+ headers: normalizeHeaders(headers),
24
+ signal: signal ? signal.aborted : null,
25
+ });
26
+ };
27
+ exports.serializeRequestInit = serializeRequestInit;
@@ -1,2 +1,11 @@
1
1
  import type { MediaUtilsAudioData } from './types';
2
- export declare const useAudioData: (src: string) => MediaUtilsAudioData | null;
2
+ export type UseAudioDataOptions = {
3
+ sampleRate?: number;
4
+ /**
5
+ * Captured only from the first render and passed to `fetch()`.
6
+ * Updates after mount are ignored so hooks do not depend on a new object
7
+ * identity every render (e.g. inline `{credentials: 'include'}`).
8
+ */
9
+ requestInit?: RequestInit;
10
+ };
11
+ export declare const useAudioData: (src: string, options?: UseAudioDataOptions | undefined) => MediaUtilsAudioData | null;
@@ -8,7 +8,7 @@ const get_audio_data_1 = require("./get-audio-data");
8
8
  * @description Wraps the getAudioData() function into a hook and does three things: keeps the audio data in a state, wraps the function in a delayRender() / continueRender() pattern, and handles the case where the component gets unmounted while fetching is in progress to prevent React errors.
9
9
  * @see [Documentation](https://www.remotion.dev/docs/use-audio-data)
10
10
  */
11
- const useAudioData = (src) => {
11
+ const useAudioData = (src, options) => {
12
12
  if (!src) {
13
13
  throw new TypeError("useAudioData requires a 'src' parameter");
14
14
  }
@@ -22,10 +22,14 @@ const useAudioData = (src) => {
22
22
  }, []);
23
23
  const [metadata, setMetadata] = (0, react_1.useState)(null);
24
24
  const { delayRender, continueRender } = (0, remotion_1.useDelayRender)();
25
+ const sampleRate = options === null || options === void 0 ? void 0 : options.sampleRate;
26
+ const [initialRequestInit] = (0, react_1.useState)(options === null || options === void 0 ? void 0 : options.requestInit);
25
27
  const fetchMetadata = (0, react_1.useCallback)(async () => {
26
28
  const handle = delayRender(`Waiting for audio metadata with src="${src}" to be loaded`);
27
29
  try {
28
- const data = await (0, get_audio_data_1.getAudioData)(src);
30
+ const data = await (0, get_audio_data_1.getAudioData)(src, sampleRate === undefined && initialRequestInit === undefined
31
+ ? undefined
32
+ : { sampleRate, requestInit: initialRequestInit });
29
33
  if (mountState.current.isMounted) {
30
34
  setMetadata(data);
31
35
  }
@@ -34,7 +38,7 @@ const useAudioData = (src) => {
34
38
  (0, remotion_1.cancelRender)(err);
35
39
  }
36
40
  continueRender(handle);
37
- }, [src, delayRender, continueRender]);
41
+ }, [src, sampleRate, initialRequestInit, delayRender, continueRender]);
38
42
  (0, react_1.useLayoutEffect)(() => {
39
43
  fetchMetadata();
40
44
  }, [fetchMetadata]);
@@ -5,9 +5,15 @@ export type UseWindowedAudioDataOptions = {
5
5
  fps: number;
6
6
  windowInSeconds: number;
7
7
  channelIndex?: number;
8
+ /**
9
+ * Captured only from the first render and passed to Mediabunny `UrlSource`.
10
+ * Updates after mount are ignored so hooks do not depend on a new object
11
+ * identity every render (e.g. inline `{credentials: 'include'}`).
12
+ */
13
+ requestInit?: RequestInit;
8
14
  };
9
15
  export type UseWindowedAudioDataReturnValue = {
10
16
  audioData: MediaUtilsAudioData | null;
11
17
  dataOffsetInSeconds: number;
12
18
  };
13
- export declare const useWindowedAudioData: ({ src, frame, fps, windowInSeconds, channelIndex, }: UseWindowedAudioDataOptions) => UseWindowedAudioDataReturnValue;
19
+ export declare const useWindowedAudioData: ({ src, frame, fps, windowInSeconds, channelIndex, requestInit, }: UseWindowedAudioDataOptions) => UseWindowedAudioDataReturnValue;
@@ -8,12 +8,13 @@ const combine_float32_arrays_1 = require("./combine-float32-arrays");
8
8
  const get_partial_audio_data_1 = require("./get-partial-audio-data");
9
9
  const is_remote_asset_1 = require("./is-remote-asset");
10
10
  const warnedMatroska = {};
11
- const useWindowedAudioData = ({ src, frame, fps, windowInSeconds, channelIndex = 0, }) => {
11
+ const useWindowedAudioData = ({ src, frame, fps, windowInSeconds, channelIndex = 0, requestInit, }) => {
12
12
  const isMounted = (0, react_1.useRef)(true);
13
13
  const [audioUtils, setAudioUtils] = (0, react_1.useState)(null);
14
14
  const [waveFormMap, setWaveformMap] = (0, react_1.useState)({});
15
15
  const requests = (0, react_1.useRef)({});
16
16
  const [initialWindowInSeconds] = (0, react_1.useState)(windowInSeconds);
17
+ const [initialRequestInit] = (0, react_1.useState)(requestInit);
17
18
  if (windowInSeconds !== initialWindowInSeconds) {
18
19
  throw new Error('windowInSeconds cannot be changed dynamically');
19
20
  }
@@ -42,7 +43,7 @@ const useWindowedAudioData = ({ src, frame, fps, windowInSeconds, channelIndex =
42
43
  signal.addEventListener('abort', cont, { once: true });
43
44
  const input = new mediabunny_1.Input({
44
45
  formats: mediabunny_1.ALL_FORMATS,
45
- source: new mediabunny_1.UrlSource(src),
46
+ source: new mediabunny_1.UrlSource(src, initialRequestInit ? { requestInit: initialRequestInit } : undefined),
46
47
  });
47
48
  const onAbort = () => {
48
49
  input.dispose();
@@ -98,7 +99,7 @@ const useWindowedAudioData = ({ src, frame, fps, windowInSeconds, channelIndex =
98
99
  signal.removeEventListener('abort', cont);
99
100
  signal.removeEventListener('abort', onAbort);
100
101
  }
101
- }, [src, delayRender, continueRender, channelIndex]);
102
+ }, [src, delayRender, continueRender, channelIndex, initialRequestInit]);
102
103
  (0, react_1.useLayoutEffect)(() => {
103
104
  const controller = new AbortController();
104
105
  fetchMetadata(controller.signal);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "url": "https://github.com/remotion-dev/remotion/tree/main/packages/media-utils"
4
4
  },
5
5
  "name": "@remotion/media-utils",
6
- "version": "4.0.457",
6
+ "version": "4.0.459",
7
7
  "description": "Utilities for working with media files",
8
8
  "main": "dist/index.js",
9
9
  "sideEffects": false,
@@ -21,7 +21,7 @@
21
21
  "url": "https://github.com/remotion-dev/remotion/issues"
22
22
  },
23
23
  "dependencies": {
24
- "remotion": "4.0.457",
24
+ "remotion": "4.0.459",
25
25
  "mediabunny": "1.42.0"
26
26
  },
27
27
  "peerDependencies": {
@@ -29,7 +29,7 @@
29
29
  "react-dom": ">=16.8.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@remotion/eslint-config-internal": "4.0.457",
32
+ "@remotion/eslint-config-internal": "4.0.459",
33
33
  "eslint": "9.19.0",
34
34
  "@typescript/native-preview": "7.0.0-dev.20260217.1"
35
35
  },