@remotion/media-utils 3.0.11 → 3.0.15

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.
@@ -1 +1,4 @@
1
- export declare const createSmoothSvgPath: (points: [number, number][]) => string | null;
1
+ export declare const smoothenSvgPath: (points: [
2
+ number,
3
+ number
4
+ ][]) => string;
@@ -1,29 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createSmoothSvgPath = void 0;
4
- const createSmoothSvgPath = (points) => {
5
- return points.reduce((acc, point, i, a) => {
3
+ exports.smoothenSvgPath = void 0;
4
+ const line = (pointA, pointB) => {
5
+ const lengthX = pointB[0] - pointA[0];
6
+ const lengthY = pointB[1] - pointA[1];
7
+ return {
8
+ length: Math.sqrt(lengthX ** 2 + lengthY ** 2),
9
+ angle: Math.atan2(lengthY, lengthX),
10
+ };
11
+ };
12
+ const controlPoint = (current, previous, next, reverse) => {
13
+ const p = previous || current;
14
+ const n = next || current;
15
+ // The smoothing ratio
16
+ const smoothing = 0.2;
17
+ // Properties of the opposed-line
18
+ const o = line(p, n);
19
+ const angle = o.angle + (reverse ? Math.PI : 0);
20
+ const length = o.length * smoothing;
21
+ const x = current[0] + Math.cos(angle) * length;
22
+ const y = current[1] + Math.sin(angle) * length;
23
+ return [x, y];
24
+ };
25
+ const smoothenSvgPath = (points) => {
26
+ return points.reduce((acc, current, i, a) => {
6
27
  if (i === 0) {
7
- return `M ${point[0]},${point[1]}`;
8
- }
9
- const p0 = a[i - 2] || a[i - 1];
10
- const x0 = p0[0];
11
- const y0 = p0[1];
12
- const p1 = a[i - 1];
13
- const x1 = p1[0];
14
- const y1 = p1[1];
15
- const x = point[0];
16
- const y = point[1];
17
- const cp1x = (2 * x0 + x1) / 3;
18
- const cp1y = (2 * y0 + y1) / 3;
19
- const cp2x = (x0 + 2 * x1) / 3;
20
- const cp2y = (y0 + 2 * y1) / 3;
21
- const cp3x = (x0 + 4 * x1 + x) / 6;
22
- const cp3y = (y0 + 4 * y1 + y) / 6;
23
- if (i === a.length - 1) {
24
- return `${acc} C ${cp1x},${cp1y} ${cp2x},${cp2y} ${cp3x},${cp3y} C${x},${y} ${x},${y} ${x},${y}`;
28
+ return `M ${current[0]},${current[1]}`;
25
29
  }
26
- return `${acc} C ${cp1x},${cp1y} ${cp2x},${cp2y} ${cp3x},${cp3y}`;
30
+ const [x, y] = current;
31
+ const previous = a[i - 1];
32
+ const twoPrevious = a[i - 2];
33
+ const next = a[i + 1];
34
+ const [cp1x, cp1y] = controlPoint(previous, twoPrevious, current, false);
35
+ const [cp2x, cp2y] = controlPoint(current, previous, next, true);
36
+ return `${acc} C ${cp1x},${cp1y} ${cp2x},${cp2y} ${x},${y}`;
27
37
  }, '');
28
38
  };
29
- exports.createSmoothSvgPath = createSmoothSvgPath;
39
+ exports.smoothenSvgPath = smoothenSvgPath;
@@ -19,6 +19,11 @@ const fn = (src) => {
19
19
  reject(video.error);
20
20
  cleanup();
21
21
  };
22
+ const pixels = video.videoHeight * video.videoWidth;
23
+ if (pixels === 0) {
24
+ reject(new Error('Unable to determine video metadata'));
25
+ return;
26
+ }
22
27
  const onLoadedMetadata = () => {
23
28
  const metadata = {
24
29
  durationInSeconds: video.duration,
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -0,0 +1 @@
1
+ export declare const validateChannel: (channel: unknown, numberOfChannels: number) => void;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateChannel = void 0;
4
+ const validateChannel = (channel, numberOfChannels) => {
5
+ if (typeof channel !== 'number') {
6
+ throw new TypeError(`"channel" must be a number`);
7
+ }
8
+ if (channel % 1 !== 0) {
9
+ throw new TypeError(`"channel" must an integer, got ${channel}`);
10
+ }
11
+ if (Number.isNaN(channel)) {
12
+ throw new TypeError(`The channel parameter is NaN.`);
13
+ }
14
+ if (channel < 0) {
15
+ throw new TypeError('"channel" cannot be negative');
16
+ }
17
+ if (channel > numberOfChannels - 1) {
18
+ throw new TypeError(`"channel" must be ${numberOfChannels - 1} or lower. The audio has ${numberOfChannels} channels`);
19
+ }
20
+ };
21
+ exports.validateChannel = validateChannel;
@@ -5,6 +5,7 @@ declare type FnParameters = {
5
5
  fps: number;
6
6
  windowInSeconds: number;
7
7
  numberOfSamples: number;
8
+ channel: number;
8
9
  };
9
10
  export declare const visualizeAudioWaveform: ({ ...parameters }: FnParameters) => number[];
10
11
  export {};
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.visualizeAudioWaveform = void 0;
4
4
  const get_waveform_portion_1 = require("./get-waveform-portion");
5
5
  const cache = {};
6
- const visualizeAudioWaveformFrame = ({ audioData, frame, fps, numberOfSamples, windowInSeconds, }) => {
6
+ const visualizeAudioWaveformFrame = ({ audioData, frame, fps, numberOfSamples, windowInSeconds, channel, }) => {
7
7
  if (windowInSeconds * audioData.sampleRate < numberOfSamples) {
8
8
  throw new TypeError(windowInSeconds +
9
9
  's audiodata does not have ' +
@@ -15,15 +15,14 @@ const visualizeAudioWaveformFrame = ({ audioData, frame, fps, numberOfSamples, w
15
15
  return cache[cacheKey];
16
16
  }
17
17
  const time = frame / fps;
18
- const max = audioData.durationInSeconds - windowInSeconds / 2;
19
- const min = windowInSeconds / 2;
20
- const startTimeInSeconds = Math.min(max, Math.max(min, time - windowInSeconds / 2));
18
+ const startTimeInSeconds = time - windowInSeconds / 2;
21
19
  return (0, get_waveform_portion_1.getWaveformPortion)({
22
20
  audioData,
23
21
  startTimeInSeconds,
24
22
  durationInSeconds: windowInSeconds,
25
23
  numberOfSamples,
26
24
  outputRange: 'minus-one-to-one',
25
+ channel,
27
26
  });
28
27
  };
29
28
  const visualizeAudioWaveform = ({ ...parameters }) => {
@@ -31,7 +31,7 @@ const visualizeAudio = ({ smoothing = true, ...parameters }) => {
31
31
  const all = toSmooth.map((s) => {
32
32
  return visualizeAudioFrame({ ...parameters, frame: s });
33
33
  });
34
- return new Array(parameters.numberOfSamples).fill(true).map((x, i) => {
34
+ return new Array(parameters.numberOfSamples).fill(true).map((_x, i) => {
35
35
  return (new Array(toSmooth.length)
36
36
  .fill(true)
37
37
  .map((_, j) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remotion/media-utils",
3
- "version": "3.0.11",
3
+ "version": "3.0.15",
4
4
  "description": "Utility functions for audio and video",
5
5
  "main": "dist/index.js",
6
6
  "sideEffects": false,
@@ -18,7 +18,7 @@
18
18
  "url": "https://github.com/remotion-dev/remotion/issues"
19
19
  },
20
20
  "dependencies": {
21
- "remotion": "3.0.11"
21
+ "remotion": "3.0.15"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "react": ">=16.8.0",
@@ -31,7 +31,7 @@
31
31
  "eslint": "8.13.0",
32
32
  "prettier": "^2.0.5",
33
33
  "prettier-plugin-organize-imports": "^2.3.4",
34
- "typescript": "^4.5.5"
34
+ "typescript": "^4.7.0"
35
35
  },
36
36
  "keywords": [
37
37
  "remotion",
@@ -44,5 +44,5 @@
44
44
  "publishConfig": {
45
45
  "access": "public"
46
46
  },
47
- "gitHead": "7bdd2de3305f669cefecfdbda7f555df1480d9c9"
47
+ "gitHead": "955b43714a53713963f862d3e9aec86de85f1ebd"
48
48
  }