@remotion/media-utils 4.0.245 → 4.0.246
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.
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.
|
|
6
|
+
"version": "4.0.246",
|
|
7
7
|
"description": "Utilities for working with media files",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"sideEffects": false,
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"url": "https://github.com/remotion-dev/remotion/issues"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"remotion": "4.0.
|
|
16
|
+
"remotion": "4.0.246"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"react": ">=16.8.0",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"eslint": "9.14.0",
|
|
24
|
-
"@remotion/eslint-config-internal": "4.0.
|
|
24
|
+
"@remotion/eslint-config-internal": "4.0.246"
|
|
25
25
|
},
|
|
26
26
|
"keywords": [
|
|
27
27
|
"remotion",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const getPartialAudioData: (src: string) => Promise<void>;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPartialAudioData = void 0;
|
|
4
|
-
const fetch_with_cors_catch_1 = require("./fetch-with-cors-catch");
|
|
5
|
-
const toUint32 = (bytes) => {
|
|
6
|
-
if (bytes.length !== 4) {
|
|
7
|
-
throw new Error('toUint32() requires exactly 4 bytes');
|
|
8
|
-
}
|
|
9
|
-
const val1 = bytes[3];
|
|
10
|
-
const val2 = bytes[2];
|
|
11
|
-
const val3 = bytes[1];
|
|
12
|
-
const val4 = bytes[0];
|
|
13
|
-
return (val1 << 24) | (val2 << 16) | (val3 << 8) | val4;
|
|
14
|
-
};
|
|
15
|
-
const toUint16 = (bytes) => {
|
|
16
|
-
if (bytes.length !== 2) {
|
|
17
|
-
throw new Error('toUint16() requires exactly 2 bytes');
|
|
18
|
-
}
|
|
19
|
-
const val1 = bytes[1];
|
|
20
|
-
const val2 = bytes[0];
|
|
21
|
-
return (val1 << 8) | val2;
|
|
22
|
-
};
|
|
23
|
-
const getPartialAudioData = async (src) => {
|
|
24
|
-
const response = await (0, fetch_with_cors_catch_1.fetchWithCorsCatch)(src, {
|
|
25
|
-
headers: {
|
|
26
|
-
range: 'bytes=0-256',
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
if (response.status !== 206) {
|
|
30
|
-
throw new Error(`Tried to read bytes 0-256 from ${src}, but the response status code was not 206. This means the server might not support returning a partial response.`);
|
|
31
|
-
}
|
|
32
|
-
const buffer = await response.arrayBuffer();
|
|
33
|
-
const uintArray = new Uint8Array(buffer);
|
|
34
|
-
const header = uintArray.slice(0, 44);
|
|
35
|
-
const shouldBeRiff = new TextDecoder().decode(uintArray.slice(0, 4));
|
|
36
|
-
if (shouldBeRiff !== 'RIFF') {
|
|
37
|
-
throw new Error('getPartialAudioData() requires a WAVE file, but the first bytes are not RIFF. ');
|
|
38
|
-
}
|
|
39
|
-
const size = toUint32(uintArray.slice(4, 8));
|
|
40
|
-
const shouldBeWAVE = new TextDecoder().decode(uintArray.slice(8, 12));
|
|
41
|
-
if (shouldBeWAVE !== 'WAVE') {
|
|
42
|
-
throw new Error('getPartialAudioData() requires a WAVE file, but the bytes 8-11 are not "WAVE". ');
|
|
43
|
-
}
|
|
44
|
-
const shouldBeFmt = new TextDecoder().decode(uintArray.slice(12, 16));
|
|
45
|
-
if (shouldBeFmt !== 'fmt ') {
|
|
46
|
-
throw new Error('getPartialAudioData() requires a WAVE file, but the bytes 12-15 are not "fmt ". ');
|
|
47
|
-
}
|
|
48
|
-
const chunkSize = toUint32(uintArray.slice(16, 20));
|
|
49
|
-
const audioFormat = toUint16(uintArray.slice(20, 22));
|
|
50
|
-
if (audioFormat !== 1) {
|
|
51
|
-
throw new Error('getPartialAudioData() supports only a WAVE file with PCM audio format, but the audio format is not PCM. ');
|
|
52
|
-
}
|
|
53
|
-
const numberOfChannels = toUint16(uintArray.slice(22, 24));
|
|
54
|
-
const sampleRate = toUint32(uintArray.slice(24, 28));
|
|
55
|
-
const byteRate = toUint32(uintArray.slice(28, 32));
|
|
56
|
-
const blockAlign = toUint16(uintArray.slice(32, 34));
|
|
57
|
-
const bitsPerSample = toUint16(uintArray.slice(34, 36));
|
|
58
|
-
let offset = 36;
|
|
59
|
-
const shouldBeDataOrList = new TextDecoder().decode(uintArray.slice(offset, offset + 4));
|
|
60
|
-
if (shouldBeDataOrList === 'LIST') {
|
|
61
|
-
const listSize = toUint32(uintArray.slice(40, 44));
|
|
62
|
-
offset += listSize;
|
|
63
|
-
offset += 8;
|
|
64
|
-
}
|
|
65
|
-
const shouldBeData = new TextDecoder().decode(uintArray.slice(offset, offset + 4));
|
|
66
|
-
if (shouldBeData !== 'data') {
|
|
67
|
-
throw new Error('getPartialAudioData() requires a WAVE file, but the bytes 36-39 are not "data". ');
|
|
68
|
-
}
|
|
69
|
-
const dataSize = toUint32(uintArray.slice(offset + 4, offset + 8));
|
|
70
|
-
const numSamples = parseInt((chunkSize / blockAlign), 10);
|
|
71
|
-
console.log({
|
|
72
|
-
response,
|
|
73
|
-
buffer,
|
|
74
|
-
header,
|
|
75
|
-
size,
|
|
76
|
-
chunkSize,
|
|
77
|
-
audioFormat,
|
|
78
|
-
numberOfChannels,
|
|
79
|
-
sampleRate,
|
|
80
|
-
byteRate,
|
|
81
|
-
blockAlign,
|
|
82
|
-
bitsPerSample,
|
|
83
|
-
dataSize,
|
|
84
|
-
numSamples,
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
exports.getPartialAudioData = getPartialAudioData;
|