@theia/ffmpeg 1.22.0

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-ffmpeg.d.ts","sourceRoot":"","sources":["../src/check-ffmpeg.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAElF,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AAEnC,MAAM,WAAW,kBAAmB,SAAQ,MAAM,CAAC,aAAa;IAC5D,IAAI,CAAC,EAAE,OAAO,CAAA;CACjB;AAED,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;CAC/B;AAED,eAAO,MAAM,wBAAwB,aAA2B,CAAC;AAEjE,wBAAsB,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CA0BjF"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ /********************************************************************************
3
+ * Copyright (C) 2019 Ericsson and others.
4
+ *
5
+ * This program and the accompanying materials are made available under the
6
+ * terms of the Eclipse Public License v. 2.0 which is available at
7
+ * http://www.eclipse.org/legal/epl-2.0.
8
+ *
9
+ * This Source Code may also be made available under the following Secondary
10
+ * Licenses when the conditions for such availability set forth in the Eclipse
11
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ * with the GNU Classpath Exception which is available at
13
+ * https://www.gnu.org/software/classpath/license.html.
14
+ *
15
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
+ ********************************************************************************/
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.checkFfmpeg = exports.KNOWN_PROPRIETARY_CODECS = void 0;
19
+ const ffmpeg = require("./ffmpeg");
20
+ exports.KNOWN_PROPRIETARY_CODECS = new Set(['h264', 'aac']);
21
+ async function checkFfmpeg(options = {}) {
22
+ const { ffmpegPath = ffmpeg.ffmpegAbsolutePath(options), json = false, } = options;
23
+ const codecs = ffmpeg.getFfmpegCodecs(ffmpegPath);
24
+ const free = [];
25
+ const proprietary = [];
26
+ for (const codec of codecs) {
27
+ if (exports.KNOWN_PROPRIETARY_CODECS.has(codec.name.toLowerCase())) {
28
+ proprietary.push(codec);
29
+ }
30
+ else {
31
+ free.push(codec);
32
+ }
33
+ }
34
+ if (json) {
35
+ // Pretty format JSON on stdout.
36
+ const result = { free, proprietary };
37
+ console.log(JSON.stringify(result, undefined, 2));
38
+ }
39
+ if (proprietary.length > 0) {
40
+ // Should be displayed on stderr to not pollute the JSON on stdout.
41
+ throw new Error(`${proprietary.length} proprietary codecs found\n${proprietary.map(codec => `> ${codec.name} detected (${codec.longName})`).join('\n')}`);
42
+ }
43
+ // Print to stderr to not pollute the JSON on stdout.
44
+ console.warn(`"${ffmpegPath}" does not contain proprietary codecs (${codecs.length} found).`);
45
+ }
46
+ exports.checkFfmpeg = checkFfmpeg;
47
+ //# sourceMappingURL=check-ffmpeg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-ffmpeg.js","sourceRoot":"","sources":["../src/check-ffmpeg.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;;AAElF,mCAAmC;AAWtB,QAAA,wBAAwB,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;AAE1D,KAAK,UAAU,WAAW,CAAC,UAA8B,EAAE;IAC9D,MAAM,EACF,UAAU,GAAG,MAAM,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAC/C,IAAI,GAAG,KAAK,GACf,GAAG,OAAO,CAAC;IACZ,MAAM,MAAM,GAAG,MAAM,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;IAClD,MAAM,IAAI,GAAG,EAAE,CAAC;IAChB,MAAM,WAAW,GAAG,EAAE,CAAC;IACvB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;QACxB,IAAI,gCAAwB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE;YACxD,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SAC3B;aAAM;YACH,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACpB;KACJ;IACD,IAAI,IAAI,EAAE;QACN,gCAAgC;QAChC,MAAM,MAAM,GAAsB,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;QACxD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;KACrD;IACD,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE;QACxB,mEAAmE;QACnE,MAAM,IAAI,KAAK,CAAC,GAAG,WAAW,CAAC,MAAM,8BAA8B,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,KAAK,CAAC,IAAI,cAAc,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;KAC7J;IACD,qDAAqD;IACrD,OAAO,CAAC,IAAI,CAAC,IAAI,UAAU,0CAA0C,MAAM,CAAC,MAAM,UAAU,CAAC,CAAC;AAClG,CAAC;AA1BD,kCA0BC"}
@@ -0,0 +1,61 @@
1
+ /********************************************************************************
2
+ * Copyright (C) 2019 Ericsson and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+ /// <reference types="node" />
17
+ export interface Codec {
18
+ id: number;
19
+ name: string;
20
+ longName: string;
21
+ }
22
+ export interface FfmpegNativeAddon {
23
+ codecs(ffmpegPath: string): Codec[];
24
+ }
25
+ declare let _FFMPEG: FfmpegNativeAddon;
26
+ export { _FFMPEG };
27
+ export interface FfmpegNameAndLocation {
28
+ /**
29
+ * Name with extension of the shared library.
30
+ */
31
+ name: string;
32
+ /**
33
+ * Relative location of the file from Electron's dist root.
34
+ */
35
+ location: string;
36
+ }
37
+ export interface FfmpegOptions {
38
+ electronVersion?: string;
39
+ electronDist?: string;
40
+ ffmpegPath?: string;
41
+ platform?: NodeJS.Platform;
42
+ }
43
+ /**
44
+ * @returns name and relative path from Electron's root where FFMPEG is located at.
45
+ */
46
+ export declare function ffmpegNameAndLocation({ platform }?: FfmpegOptions): FfmpegNameAndLocation;
47
+ /**
48
+ * @returns relative ffmpeg shared library path from the Electron distribution root.
49
+ */
50
+ export declare function ffmpegRelativePath(options?: FfmpegOptions): string;
51
+ /**
52
+ * @returns absolute ffmpeg shared library path.
53
+ */
54
+ export declare function ffmpegAbsolutePath(options?: FfmpegOptions): string;
55
+ /**
56
+ * Dynamically link to `ffmpegPath` and use FFMPEG APIs to list the included `Codec`s.
57
+ * @param ffmpegPath absolute path the the FFMPEG shared library.
58
+ * @returns list of codecs for the given ffmpeg shared library.
59
+ */
60
+ export declare function getFfmpegCodecs(ffmpegPath: string): Codec[];
61
+ //# sourceMappingURL=ffmpeg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ffmpeg.d.ts","sourceRoot":"","sources":["../src/ffmpeg.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;;AAIlF,MAAM,WAAW,KAAK;IAClB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,iBAAiB;IAC9B,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,KAAK,EAAE,CAAA;CACtC;AAED,QAAA,IAAI,OAAO,EAAE,iBAAiB,CAAC;AAU/B,OAAO,EAAE,OAAO,EAAE,CAAC;AAEnB,MAAM,WAAW,qBAAqB;IAClC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,aAAa;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAA;CAC7B;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,EAClC,QAA2B,EAC9B,GAAE,aAAkB,GAAG,qBAAqB,CAoB5C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,aAAkB,GAAG,MAAM,CAGtE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,aAAkB,GAAG,MAAM,CAKtE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,KAAK,EAAE,CAE3D"}
package/lib/ffmpeg.js ADDED
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ /********************************************************************************
3
+ * Copyright (C) 2019 Ericsson and others.
4
+ *
5
+ * This program and the accompanying materials are made available under the
6
+ * terms of the Eclipse Public License v. 2.0 which is available at
7
+ * http://www.eclipse.org/legal/epl-2.0.
8
+ *
9
+ * This Source Code may also be made available under the following Secondary
10
+ * Licenses when the conditions for such availability set forth in the Eclipse
11
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ * with the GNU Classpath Exception which is available at
13
+ * https://www.gnu.org/software/classpath/license.html.
14
+ *
15
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
+ ********************************************************************************/
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.getFfmpegCodecs = exports.ffmpegAbsolutePath = exports.ffmpegRelativePath = exports.ffmpegNameAndLocation = exports._FFMPEG = void 0;
19
+ const path = require("path");
20
+ let _FFMPEG;
21
+ exports._FFMPEG = _FFMPEG;
22
+ try {
23
+ exports._FFMPEG = _FFMPEG = require('../build/Release/ffmpeg.node');
24
+ }
25
+ catch (error) {
26
+ if (error.code === 'MODULE_NOT_FOUND') {
27
+ exports._FFMPEG = _FFMPEG = require('../build/Debug/ffmpeg.node');
28
+ }
29
+ else {
30
+ throw error;
31
+ }
32
+ }
33
+ /**
34
+ * @returns name and relative path from Electron's root where FFMPEG is located at.
35
+ */
36
+ function ffmpegNameAndLocation({ platform = process.platform } = {}) {
37
+ switch (platform) {
38
+ case 'darwin':
39
+ return {
40
+ name: 'libffmpeg.dylib',
41
+ location: 'Electron.app/Contents/Frameworks/Electron Framework.framework/Libraries/',
42
+ };
43
+ case 'win32':
44
+ return {
45
+ name: 'ffmpeg.dll',
46
+ location: '',
47
+ };
48
+ case 'linux':
49
+ return {
50
+ name: 'libffmpeg.so',
51
+ location: '',
52
+ };
53
+ default:
54
+ throw new Error(`${platform} is not supported`);
55
+ }
56
+ }
57
+ exports.ffmpegNameAndLocation = ffmpegNameAndLocation;
58
+ /**
59
+ * @returns relative ffmpeg shared library path from the Electron distribution root.
60
+ */
61
+ function ffmpegRelativePath(options = {}) {
62
+ const { location, name } = ffmpegNameAndLocation(options);
63
+ return path.join(location, name);
64
+ }
65
+ exports.ffmpegRelativePath = ffmpegRelativePath;
66
+ /**
67
+ * @returns absolute ffmpeg shared library path.
68
+ */
69
+ function ffmpegAbsolutePath(options = {}) {
70
+ const { electronDist = path.resolve(require.resolve('electron/package.json'), '..', 'dist') } = options;
71
+ return path.join(electronDist, ffmpegRelativePath(options));
72
+ }
73
+ exports.ffmpegAbsolutePath = ffmpegAbsolutePath;
74
+ /**
75
+ * Dynamically link to `ffmpegPath` and use FFMPEG APIs to list the included `Codec`s.
76
+ * @param ffmpegPath absolute path the the FFMPEG shared library.
77
+ * @returns list of codecs for the given ffmpeg shared library.
78
+ */
79
+ function getFfmpegCodecs(ffmpegPath) {
80
+ return _FFMPEG.codecs(ffmpegPath);
81
+ }
82
+ exports.getFfmpegCodecs = getFfmpegCodecs;
83
+ //# sourceMappingURL=ffmpeg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ffmpeg.js","sourceRoot":"","sources":["../src/ffmpeg.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;;AAElF,6BAA8B;AAY9B,IAAI,OAA0B,CAAC;AAUtB,0BAAO;AAThB,IAAI;IACA,kBAAA,OAAO,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC;CACrD;AAAC,OAAO,KAAK,EAAE;IACZ,IAAI,KAAK,CAAC,IAAI,KAAK,kBAAkB,EAAE;QACnC,kBAAA,OAAO,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;KACnD;SAAM;QACH,MAAM,KAAK,CAAC;KACf;CACJ;AAqBD;;GAEG;AACH,SAAgB,qBAAqB,CAAC,EAClC,QAAQ,GAAG,OAAO,CAAC,QAAQ,KACZ,EAAE;IACjB,QAAQ,QAAQ,EAAE;QACd,KAAK,QAAQ;YACT,OAAO;gBACH,IAAI,EAAE,iBAAiB;gBACvB,QAAQ,EAAE,0EAA0E;aACvF,CAAC;QACN,KAAK,OAAO;YACR,OAAO;gBACH,IAAI,EAAE,YAAY;gBAClB,QAAQ,EAAE,EAAE;aACf,CAAC;QACN,KAAK,OAAO;YACR,OAAO;gBACH,IAAI,EAAE,cAAc;gBACpB,QAAQ,EAAE,EAAE;aACf,CAAC;QACN;YACI,MAAM,IAAI,KAAK,CAAC,GAAG,QAAQ,mBAAmB,CAAC,CAAC;KACvD;AACL,CAAC;AAtBD,sDAsBC;AAED;;GAEG;AACH,SAAgB,kBAAkB,CAAC,UAAyB,EAAE;IAC1D,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAC1D,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC;AAHD,gDAGC;AAED;;GAEG;AACH,SAAgB,kBAAkB,CAAC,UAAyB,EAAE;IAC1D,MAAM,EACF,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,uBAAuB,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,EACtF,GAAG,OAAO,CAAC;IACZ,OAAO,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;AAChE,CAAC;AALD,gDAKC;AAED;;;;GAIG;AACH,SAAgB,eAAe,CAAC,UAAkB;IAC9C,OAAO,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AACtC,CAAC;AAFD,0CAEC"}
package/lib/hash.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ /********************************************************************************
2
+ * Copyright (C) 2021 Ericsson and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+ /// <reference types="node" />
17
+ export declare function hashFile(filePath: string): Promise<Buffer>;
18
+ //# sourceMappingURL=hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;;AAKlF,wBAAsB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAQhE"}
package/lib/hash.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ /********************************************************************************
3
+ * Copyright (C) 2021 Ericsson and others.
4
+ *
5
+ * This program and the accompanying materials are made available under the
6
+ * terms of the Eclipse Public License v. 2.0 which is available at
7
+ * http://www.eclipse.org/legal/epl-2.0.
8
+ *
9
+ * This Source Code may also be made available under the following Secondary
10
+ * Licenses when the conditions for such availability set forth in the Eclipse
11
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ * with the GNU Classpath Exception which is available at
13
+ * https://www.gnu.org/software/classpath/license.html.
14
+ *
15
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
+ ********************************************************************************/
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.hashFile = void 0;
19
+ const crypto = require("crypto");
20
+ const fs = require("fs-extra");
21
+ async function hashFile(filePath) {
22
+ return new Promise((resolve, reject) => {
23
+ const sha256 = crypto.createHash('sha256');
24
+ fs.createReadStream(filePath)
25
+ .on('close', () => resolve(sha256.digest()))
26
+ .on('data', data => sha256.update(data))
27
+ .on('error', reject);
28
+ });
29
+ }
30
+ exports.hashFile = hashFile;
31
+ //# sourceMappingURL=hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;;AAElF,iCAAkC;AAClC,+BAAgC;AAEzB,KAAK,UAAU,QAAQ,CAAC,QAAgB;IAC3C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnC,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAC3C,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC;aACxB,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;aAC3C,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;aACvC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;AACP,CAAC;AARD,4BAQC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ /********************************************************************************
2
+ * Copyright (C) 2021 Ericsson and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+ export * from './hash';
17
+ export * from './ffmpeg';
18
+ export * from './check-ffmpeg';
19
+ export * from './replace-ffmpeg';
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAElF,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /********************************************************************************
3
+ * Copyright (C) 2021 Ericsson and others.
4
+ *
5
+ * This program and the accompanying materials are made available under the
6
+ * terms of the Eclipse Public License v. 2.0 which is available at
7
+ * http://www.eclipse.org/legal/epl-2.0.
8
+ *
9
+ * This Source Code may also be made available under the following Secondary
10
+ * Licenses when the conditions for such availability set forth in the Eclipse
11
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ * with the GNU Classpath Exception which is available at
13
+ * https://www.gnu.org/software/classpath/license.html.
14
+ *
15
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
+ ********************************************************************************/
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
25
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ __exportStar(require("./hash"), exports);
29
+ __exportStar(require("./ffmpeg"), exports);
30
+ __exportStar(require("./check-ffmpeg"), exports);
31
+ __exportStar(require("./replace-ffmpeg"), exports);
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;;;;;;;;;;;AAElF,yCAAuB;AACvB,2CAAyB;AACzB,iDAA+B;AAC/B,mDAAiC"}
@@ -0,0 +1,19 @@
1
+ /********************************************************************************
2
+ * Copyright (C) 2019 Ericsson and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+ import * as ffmpeg from './ffmpeg';
17
+ export declare function replaceFfmpeg(options?: ffmpeg.FfmpegOptions): Promise<void>;
18
+ export declare function readElectronVersion(electronDist: string): Promise<string>;
19
+ //# sourceMappingURL=replace-ffmpeg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replace-ffmpeg.d.ts","sourceRoot":"","sources":["../src/replace-ffmpeg.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAOlF,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AAGnC,wBAAsB,aAAa,CAAC,OAAO,GAAE,MAAM,CAAC,aAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAiDrF;AAED,wBAAsB,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAI/E"}
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ /********************************************************************************
3
+ * Copyright (C) 2019 Ericsson and others.
4
+ *
5
+ * This program and the accompanying materials are made available under the
6
+ * terms of the Eclipse Public License v. 2.0 which is available at
7
+ * http://www.eclipse.org/legal/epl-2.0.
8
+ *
9
+ * This Source Code may also be made available under the following Secondary
10
+ * Licenses when the conditions for such availability set forth in the Eclipse
11
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ * with the GNU Classpath Exception which is available at
13
+ * https://www.gnu.org/software/classpath/license.html.
14
+ *
15
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
+ ********************************************************************************/
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.readElectronVersion = exports.replaceFfmpeg = void 0;
19
+ const electronGet = require("@electron/get");
20
+ const fs = require("fs-extra");
21
+ const os = require("os");
22
+ const path = require("path");
23
+ const unzipper = require("unzipper");
24
+ const ffmpeg = require("./ffmpeg");
25
+ const hash_1 = require("./hash");
26
+ async function replaceFfmpeg(options = {}) {
27
+ let shouldDownload = true;
28
+ let shouldReplace = true;
29
+ const { name: ffmpegName, location: ffmpegLocation, } = ffmpeg.ffmpegNameAndLocation(options);
30
+ const { electronDist = path.resolve(require.resolve('electron/package.json'), '..', 'dist'), electronVersion = await readElectronVersion(electronDist), ffmpegPath = path.resolve(electronDist, ffmpegLocation, ffmpegName), } = options;
31
+ const ffmpegCachedPath = path.join(os.tmpdir(), `theia-cli/cache/electron-v${electronVersion}`, ffmpegName);
32
+ if (await fs.pathExists(ffmpegCachedPath)) {
33
+ shouldDownload = false; // If the file is already cached, do not download.
34
+ console.warn('Found cached ffmpeg library.');
35
+ const [cacheHash, distHash] = await Promise.all([
36
+ hash_1.hashFile(ffmpegCachedPath),
37
+ hash_1.hashFile(ffmpegPath),
38
+ ]);
39
+ if (cacheHash.equals(distHash)) {
40
+ shouldReplace = false; // If files are already the same, do not replace.
41
+ console.warn('Hashes are equal, not replacing the ffmpeg library.');
42
+ }
43
+ }
44
+ if (shouldDownload) {
45
+ const ffmpegZipPath = await electronGet.downloadArtifact({
46
+ version: electronVersion,
47
+ artifactName: 'ffmpeg'
48
+ });
49
+ const ffmpegZip = await unzipper.Open.file(ffmpegZipPath);
50
+ const file = ffmpegZip.files.find(f => f.path.endsWith(ffmpegName));
51
+ if (!file) {
52
+ throw new Error(`Archive did not contain "${ffmpegName}".`);
53
+ }
54
+ // Extract file to cache.
55
+ await fs.mkdirp(path.dirname(ffmpegCachedPath));
56
+ await new Promise((resolve, reject) => {
57
+ file.stream()
58
+ .pipe(fs.createWriteStream(ffmpegCachedPath))
59
+ .on('finish', resolve)
60
+ .on('error', reject);
61
+ });
62
+ console.warn(`Downloaded ffmpeg shared library { version: "${electronVersion}", dist: "${electronDist}" }.`);
63
+ }
64
+ if (shouldReplace) {
65
+ await fs.copy(ffmpegCachedPath, ffmpegPath);
66
+ console.warn(`Successfully replaced "${ffmpegPath}".`);
67
+ }
68
+ }
69
+ exports.replaceFfmpeg = replaceFfmpeg;
70
+ async function readElectronVersion(electronDist) {
71
+ const electronVersionFilePath = path.resolve(electronDist, 'version');
72
+ const version = await fs.readFile(electronVersionFilePath, 'utf8');
73
+ return version.trim();
74
+ }
75
+ exports.readElectronVersion = readElectronVersion;
76
+ //# sourceMappingURL=replace-ffmpeg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replace-ffmpeg.js","sourceRoot":"","sources":["../src/replace-ffmpeg.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,146 @@
1
+ /********************************************************************************
2
+ * Copyright (C) 2019 Ericsson and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+
17
+ /**
18
+ * https://nodejs.org/docs/latest-v10.x/api/n-api.html#n_api_n_api
19
+ */
20
+ #include <node_api.h>
21
+
22
+ #include <string.h>
23
+
24
+ #include "ffmpeg.h"
25
+
26
+ /**
27
+ * Return the list of codecs registered in the FFMPEG library.
28
+ */
29
+ napi_value codecs(napi_env env, napi_callback_info info)
30
+ {
31
+ // We will reuse this `status` for all napi calls.
32
+ napi_status status;
33
+ char *error = NULL;
34
+
35
+ // Get arguments.
36
+ size_t argc = 1;
37
+ napi_value argv[1];
38
+ status = napi_get_cb_info(env, info, &argc, argv, NULL, NULL);
39
+ if (status != napi_ok || argc < 1)
40
+ {
41
+ error = "invalid arguments";
42
+ goto error;
43
+ }
44
+
45
+ // Get first argument as string.
46
+ char path[2048];
47
+ status = napi_get_value_string_utf8(env, argv[0], path, 2048, NULL);
48
+ if (status != napi_ok)
49
+ {
50
+ error = "invalid string argument";
51
+ goto error;
52
+ }
53
+
54
+ // Load ffmpeg based on the provided path.
55
+ struct FFMPEG_Library ffmpeg = NULL_FFMPEG_LIBRARY;
56
+ char *load_error = load_ffmpeg_library(&ffmpeg, path);
57
+ if (load_error != NULL)
58
+ {
59
+ error = load_error;
60
+ goto error;
61
+ }
62
+
63
+ // Create the JavaScript list that will be returned.
64
+ napi_value codecs;
65
+ status = napi_create_array(env, &codecs);
66
+ if (status != napi_ok)
67
+ {
68
+ error = "napi_create_array fail";
69
+ goto error;
70
+ }
71
+
72
+ // Iterate over the codec descriptions.
73
+ // It includes descriptions for codecs that may not be present in the library.
74
+ struct AVCodecDescriptor *descriptor = ffmpeg.avcodec_descriptor_next(NULL);
75
+ while (descriptor != NULL)
76
+ {
77
+ // Try to fetch the codec being described, returns null on missing codecs.
78
+ struct AVCodec *decoder = ffmpeg.avcodec_find_decoder(descriptor->id);
79
+ if (decoder != NULL)
80
+ {
81
+ // Create the codec object and assign the properties.
82
+ napi_value object, value;
83
+ napi_create_object(env, &object);
84
+
85
+ // id: number
86
+ napi_create_int32(env, decoder->id, &value);
87
+ napi_set_named_property(env, object, "id", value);
88
+
89
+ // name: string
90
+ napi_create_string_utf8(env, decoder->name, strlen(decoder->name), &value);
91
+ napi_set_named_property(env, object, "name", value);
92
+
93
+ // longName: string
94
+ napi_create_string_utf8(env, decoder->long_name, strlen(decoder->long_name), &value);
95
+ napi_set_named_property(env, object, "longName", value);
96
+
97
+ // Pushing into a JS array requires calling the JS method for that.
98
+ napi_value push_fn;
99
+ napi_get_named_property(env, codecs, "push", &push_fn);
100
+ napi_call_function(env, codecs, push_fn, 1, (napi_value[]){object}, NULL);
101
+ }
102
+ descriptor = ffmpeg.avcodec_descriptor_next(descriptor);
103
+ }
104
+
105
+ // Free the ffmpeg library.
106
+ char *unload_error = unload_ffmpeg_library(&ffmpeg);
107
+ if (unload_error != NULL)
108
+ {
109
+ error = unload_error;
110
+ goto error;
111
+ }
112
+
113
+ return codecs;
114
+
115
+ error:
116
+ if (error != NULL)
117
+ {
118
+ napi_throw_error(env, NULL, error);
119
+ }
120
+ return NULL;
121
+ }
122
+
123
+ /**
124
+ * https://nodejs.org/docs/latest-v10.x/api/n-api.html#n_api_module_registration
125
+ */
126
+ napi_value initialize(napi_env env, napi_value exports)
127
+ {
128
+ napi_status status;
129
+ napi_value function_codecs;
130
+
131
+ status = napi_create_function(env, NULL, 0, codecs, NULL, &function_codecs);
132
+ if (status != napi_ok)
133
+ {
134
+ return NULL;
135
+ }
136
+
137
+ status = napi_set_named_property(env, exports, "codecs", function_codecs);
138
+ if (status != napi_ok)
139
+ {
140
+ return NULL;
141
+ }
142
+
143
+ return exports;
144
+ }
145
+
146
+ NAPI_MODULE(NODE_GYP_MODULE_NAME, initialize);