@theia/ffmpeg 1.48.0 → 1.48.1

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/src/ffmpeg.ts CHANGED
@@ -1,114 +1,114 @@
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-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import path = require('path');
18
-
19
- export interface Codec {
20
- id: number
21
- name: string
22
- longName: string
23
- }
24
-
25
- export interface FfmpegNativeAddon {
26
- codecs(ffmpegPath: string): Codec[]
27
- }
28
-
29
- export interface FfmpegNameAndLocation {
30
- /**
31
- * Name with extension of the shared library.
32
- */
33
- name: string
34
- /**
35
- * Relative location of the file from Electron's dist root.
36
- */
37
- location: string
38
- }
39
-
40
- export interface FfmpegOptions {
41
- electronVersion?: string
42
- electronDist?: string
43
- ffmpegPath?: string
44
- platform?: NodeJS.Platform
45
- }
46
-
47
- /**
48
- * @internal
49
- */
50
- export function _loadFfmpegNativeAddon(): FfmpegNativeAddon {
51
- try {
52
- return require('../build/Release/ffmpeg.node');
53
- } catch (error) {
54
- if (error.code === 'MODULE_NOT_FOUND') {
55
- return require('../build/Debug/ffmpeg.node');
56
- } else {
57
- throw error;
58
- }
59
- }
60
- }
61
-
62
- /**
63
- * @returns name and relative path from Electron's root where FFMPEG is located at.
64
- */
65
- export function ffmpegNameAndLocation({
66
- platform = process.platform
67
- }: FfmpegOptions = {}): FfmpegNameAndLocation {
68
- switch (platform) {
69
- case 'darwin':
70
- return {
71
- name: 'libffmpeg.dylib',
72
- location: 'Electron.app/Contents/Frameworks/Electron Framework.framework/Libraries/',
73
- };
74
- case 'win32':
75
- return {
76
- name: 'ffmpeg.dll',
77
- location: '',
78
- };
79
- case 'linux':
80
- return {
81
- name: 'libffmpeg.so',
82
- location: '',
83
- };
84
- default:
85
- throw new Error(`${platform} is not supported`);
86
- }
87
- }
88
-
89
- /**
90
- * @returns relative ffmpeg shared library path from the Electron distribution root.
91
- */
92
- export function ffmpegRelativePath(options: FfmpegOptions = {}): string {
93
- const { location, name } = ffmpegNameAndLocation(options);
94
- return path.join(location, name);
95
- }
96
-
97
- /**
98
- * @returns absolute ffmpeg shared library path.
99
- */
100
- export function ffmpegAbsolutePath(options: FfmpegOptions = {}): string {
101
- const {
102
- electronDist = path.resolve(require.resolve('electron/package.json'), '..', 'dist')
103
- } = options;
104
- return path.join(electronDist, ffmpegRelativePath(options));
105
- }
106
-
107
- /**
108
- * Dynamically link to `ffmpegPath` and use FFMPEG APIs to list the included `Codec`s.
109
- * @param ffmpegPath absolute path the the FFMPEG shared library.
110
- * @returns list of codecs for the given ffmpeg shared library.
111
- */
112
- export function getFfmpegCodecs(ffmpegPath: string): Codec[] {
113
- return _loadFfmpegNativeAddon().codecs(ffmpegPath);
114
- }
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-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import path = require('path');
18
+
19
+ export interface Codec {
20
+ id: number
21
+ name: string
22
+ longName: string
23
+ }
24
+
25
+ export interface FfmpegNativeAddon {
26
+ codecs(ffmpegPath: string): Codec[]
27
+ }
28
+
29
+ export interface FfmpegNameAndLocation {
30
+ /**
31
+ * Name with extension of the shared library.
32
+ */
33
+ name: string
34
+ /**
35
+ * Relative location of the file from Electron's dist root.
36
+ */
37
+ location: string
38
+ }
39
+
40
+ export interface FfmpegOptions {
41
+ electronVersion?: string
42
+ electronDist?: string
43
+ ffmpegPath?: string
44
+ platform?: NodeJS.Platform
45
+ }
46
+
47
+ /**
48
+ * @internal
49
+ */
50
+ export function _loadFfmpegNativeAddon(): FfmpegNativeAddon {
51
+ try {
52
+ return require('../build/Release/ffmpeg.node');
53
+ } catch (error) {
54
+ if (error.code === 'MODULE_NOT_FOUND') {
55
+ return require('../build/Debug/ffmpeg.node');
56
+ } else {
57
+ throw error;
58
+ }
59
+ }
60
+ }
61
+
62
+ /**
63
+ * @returns name and relative path from Electron's root where FFMPEG is located at.
64
+ */
65
+ export function ffmpegNameAndLocation({
66
+ platform = process.platform
67
+ }: FfmpegOptions = {}): FfmpegNameAndLocation {
68
+ switch (platform) {
69
+ case 'darwin':
70
+ return {
71
+ name: 'libffmpeg.dylib',
72
+ location: 'Electron.app/Contents/Frameworks/Electron Framework.framework/Libraries/',
73
+ };
74
+ case 'win32':
75
+ return {
76
+ name: 'ffmpeg.dll',
77
+ location: '',
78
+ };
79
+ case 'linux':
80
+ return {
81
+ name: 'libffmpeg.so',
82
+ location: '',
83
+ };
84
+ default:
85
+ throw new Error(`${platform} is not supported`);
86
+ }
87
+ }
88
+
89
+ /**
90
+ * @returns relative ffmpeg shared library path from the Electron distribution root.
91
+ */
92
+ export function ffmpegRelativePath(options: FfmpegOptions = {}): string {
93
+ const { location, name } = ffmpegNameAndLocation(options);
94
+ return path.join(location, name);
95
+ }
96
+
97
+ /**
98
+ * @returns absolute ffmpeg shared library path.
99
+ */
100
+ export function ffmpegAbsolutePath(options: FfmpegOptions = {}): string {
101
+ const {
102
+ electronDist = path.resolve(require.resolve('electron/package.json'), '..', 'dist')
103
+ } = options;
104
+ return path.join(electronDist, ffmpegRelativePath(options));
105
+ }
106
+
107
+ /**
108
+ * Dynamically link to `ffmpegPath` and use FFMPEG APIs to list the included `Codec`s.
109
+ * @param ffmpegPath absolute path the the FFMPEG shared library.
110
+ * @returns list of codecs for the given ffmpeg shared library.
111
+ */
112
+ export function getFfmpegCodecs(ffmpegPath: string): Codec[] {
113
+ return _loadFfmpegNativeAddon().codecs(ffmpegPath);
114
+ }
package/src/hash.ts CHANGED
@@ -1,28 +1,28 @@
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-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import crypto = require('crypto');
18
- import fs = require('fs-extra');
19
-
20
- export async function hashFile(filePath: string): Promise<Buffer> {
21
- return new Promise((resolve, reject) => {
22
- const sha256 = crypto.createHash('sha256');
23
- fs.createReadStream(filePath)
24
- .on('close', () => resolve(sha256.digest()))
25
- .on('data', data => sha256.update(data))
26
- .on('error', reject);
27
- });
28
- }
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-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import crypto = require('crypto');
18
+ import fs = require('fs-extra');
19
+
20
+ export async function hashFile(filePath: string): Promise<Buffer> {
21
+ return new Promise((resolve, reject) => {
22
+ const sha256 = crypto.createHash('sha256');
23
+ fs.createReadStream(filePath)
24
+ .on('close', () => resolve(sha256.digest()))
25
+ .on('data', data => sha256.update(data))
26
+ .on('error', reject);
27
+ });
28
+ }
package/src/index.ts CHANGED
@@ -1,20 +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-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- export * from './hash';
18
- export * from './ffmpeg';
19
- export * from './check-ffmpeg';
20
- export * from './replace-ffmpeg';
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-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ export * from './hash';
18
+ export * from './ffmpeg';
19
+ export * from './check-ffmpeg';
20
+ export * from './replace-ffmpeg';
@@ -1,80 +1,80 @@
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-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import electronGet = require('@electron/get');
18
- import fs = require('fs-extra');
19
- import os = require('os');
20
- import path = require('path');
21
- import unzipper = require('unzipper');
22
- import * as ffmpeg from './ffmpeg';
23
- import { hashFile } from './hash';
24
-
25
- export async function replaceFfmpeg(options: ffmpeg.FfmpegOptions = {}): Promise<void> {
26
- let shouldDownload = true;
27
- let shouldReplace = true;
28
- const {
29
- name: ffmpegName,
30
- location: ffmpegLocation,
31
- } = ffmpeg.ffmpegNameAndLocation(options);
32
- const {
33
- electronDist = path.resolve(require.resolve('electron/package.json'), '..', 'dist'),
34
- electronVersion = await readElectronVersion(electronDist),
35
- ffmpegPath = path.resolve(electronDist, ffmpegLocation, ffmpegName),
36
- } = options;
37
- const ffmpegCachedPath = path.join(os.tmpdir(), `theia-cli/cache/electron-v${electronVersion}`, ffmpegName);
38
- if (await fs.pathExists(ffmpegCachedPath)) {
39
- shouldDownload = false; // If the file is already cached, do not download.
40
- console.warn('Found cached ffmpeg library.');
41
- const [cacheHash, distHash] = await Promise.all([
42
- hashFile(ffmpegCachedPath),
43
- hashFile(ffmpegPath),
44
- ]);
45
- if (cacheHash.equals(distHash)) {
46
- shouldReplace = false; // If files are already the same, do not replace.
47
- console.warn('Hashes are equal, not replacing the ffmpeg library.');
48
- }
49
- }
50
- if (shouldDownload) {
51
- const ffmpegZipPath = await electronGet.downloadArtifact({
52
- version: electronVersion,
53
- artifactName: 'ffmpeg'
54
- });
55
- const ffmpegZip = await unzipper.Open.file(ffmpegZipPath);
56
- const file = ffmpegZip.files.find(f => f.path.endsWith(ffmpegName));
57
- if (!file) {
58
- throw new Error(`Archive did not contain "${ffmpegName}".`);
59
- }
60
- // Extract file to cache.
61
- await fs.mkdirp(path.dirname(ffmpegCachedPath));
62
- await new Promise((resolve, reject) => {
63
- file.stream()
64
- .pipe(fs.createWriteStream(ffmpegCachedPath))
65
- .on('finish', resolve)
66
- .on('error', reject);
67
- });
68
- console.warn(`Downloaded ffmpeg shared library { version: "${electronVersion}", dist: "${electronDist}" }.`);
69
- }
70
- if (shouldReplace) {
71
- await fs.copy(ffmpegCachedPath, ffmpegPath);
72
- console.warn(`Successfully replaced "${ffmpegPath}".`);
73
- }
74
- }
75
-
76
- export async function readElectronVersion(electronDist: string): Promise<string> {
77
- const electronVersionFilePath = path.resolve(electronDist, 'version');
78
- const version = await fs.readFile(electronVersionFilePath, 'utf8');
79
- return version.trim();
80
- }
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-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import electronGet = require('@electron/get');
18
+ import fs = require('fs-extra');
19
+ import os = require('os');
20
+ import path = require('path');
21
+ import unzipper = require('unzipper');
22
+ import * as ffmpeg from './ffmpeg';
23
+ import { hashFile } from './hash';
24
+
25
+ export async function replaceFfmpeg(options: ffmpeg.FfmpegOptions = {}): Promise<void> {
26
+ let shouldDownload = true;
27
+ let shouldReplace = true;
28
+ const {
29
+ name: ffmpegName,
30
+ location: ffmpegLocation,
31
+ } = ffmpeg.ffmpegNameAndLocation(options);
32
+ const {
33
+ electronDist = path.resolve(require.resolve('electron/package.json'), '..', 'dist'),
34
+ electronVersion = await readElectronVersion(electronDist),
35
+ ffmpegPath = path.resolve(electronDist, ffmpegLocation, ffmpegName),
36
+ } = options;
37
+ const ffmpegCachedPath = path.join(os.tmpdir(), `theia-cli/cache/electron-v${electronVersion}`, ffmpegName);
38
+ if (await fs.pathExists(ffmpegCachedPath)) {
39
+ shouldDownload = false; // If the file is already cached, do not download.
40
+ console.warn('Found cached ffmpeg library.');
41
+ const [cacheHash, distHash] = await Promise.all([
42
+ hashFile(ffmpegCachedPath),
43
+ hashFile(ffmpegPath),
44
+ ]);
45
+ if (cacheHash.equals(distHash)) {
46
+ shouldReplace = false; // If files are already the same, do not replace.
47
+ console.warn('Hashes are equal, not replacing the ffmpeg library.');
48
+ }
49
+ }
50
+ if (shouldDownload) {
51
+ const ffmpegZipPath = await electronGet.downloadArtifact({
52
+ version: electronVersion,
53
+ artifactName: 'ffmpeg'
54
+ });
55
+ const ffmpegZip = await unzipper.Open.file(ffmpegZipPath);
56
+ const file = ffmpegZip.files.find(f => f.path.endsWith(ffmpegName));
57
+ if (!file) {
58
+ throw new Error(`Archive did not contain "${ffmpegName}".`);
59
+ }
60
+ // Extract file to cache.
61
+ await fs.mkdirp(path.dirname(ffmpegCachedPath));
62
+ await new Promise((resolve, reject) => {
63
+ file.stream()
64
+ .pipe(fs.createWriteStream(ffmpegCachedPath))
65
+ .on('finish', resolve)
66
+ .on('error', reject);
67
+ });
68
+ console.warn(`Downloaded ffmpeg shared library { version: "${electronVersion}", dist: "${electronDist}" }.`);
69
+ }
70
+ if (shouldReplace) {
71
+ await fs.copy(ffmpegCachedPath, ffmpegPath);
72
+ console.warn(`Successfully replaced "${ffmpegPath}".`);
73
+ }
74
+ }
75
+
76
+ export async function readElectronVersion(electronDist: string): Promise<string> {
77
+ const electronVersionFilePath = path.resolve(electronDist, 'version');
78
+ const version = await fs.readFile(electronVersionFilePath, 'utf8');
79
+ return version.trim();
80
+ }