@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/README.md +3 -3
- package/binding.gyp +29 -29
- package/lib/check-ffmpeg.d.ts +10 -10
- package/lib/check-ffmpeg.js +46 -46
- package/lib/ffmpeg.d.ts +47 -47
- package/lib/ffmpeg.js +86 -86
- package/lib/hash.d.ts +2 -2
- package/lib/hash.js +30 -30
- package/lib/index.d.ts +4 -4
- package/lib/index.js +22 -22
- package/lib/replace-ffmpeg.d.ts +3 -3
- package/lib/replace-ffmpeg.js +75 -75
- package/native/ffmpeg.c +146 -146
- package/native/ffmpeg.h +80 -80
- package/native/linux-ffmpeg.c +68 -68
- package/native/mac-ffmpeg.c +26 -26
- package/native/win-ffmpeg.c +77 -77
- package/package.json +2 -2
- package/src/check-ffmpeg.ts +56 -56
- package/src/ffmpeg.ts +114 -114
- package/src/hash.ts +28 -28
- package/src/index.ts +20 -20
- package/src/replace-ffmpeg.ts +80 -80
package/lib/replace-ffmpeg.js
CHANGED
|
@@ -1,76 +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-only 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
|
-
(0, hash_1.hashFile)(ffmpegCachedPath),
|
|
37
|
-
(0, 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;
|
|
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-only 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
|
+
(0, hash_1.hashFile)(ffmpegCachedPath),
|
|
37
|
+
(0, 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
76
|
//# sourceMappingURL=replace-ffmpeg.js.map
|
package/native/ffmpeg.c
CHANGED
|
@@ -1,146 +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-only 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);
|
|
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
|
+
/**
|
|
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);
|
package/native/ffmpeg.h
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
#ifndef FFMPEG_H
|
|
2
|
-
#define FFMPEG_H
|
|
3
|
-
/**
|
|
4
|
-
* THIS FILE REDEFINES DATA AS RETURNED BY THE FFMPEG LIBRARY.
|
|
5
|
-
* HEADER FILES ARE NOT DISTRIBUTED IN OUR SETUP, HENCE THIS.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavutil/avutil.h#L193-L201
|
|
10
|
-
*/
|
|
11
|
-
enum AVMediaType
|
|
12
|
-
{
|
|
13
|
-
_UNKNOWN_DATA_AVMediaType = -1,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L191-L653
|
|
18
|
-
*/
|
|
19
|
-
enum AVCodecID
|
|
20
|
-
{
|
|
21
|
-
__UNKNOWN_DATA_AVCodecID = 0,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L3611-L3721
|
|
26
|
-
*/
|
|
27
|
-
struct AVCodec
|
|
28
|
-
{
|
|
29
|
-
const char *name, *long_name;
|
|
30
|
-
enum AVMediaType type;
|
|
31
|
-
enum AVCodecID id;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L660-L688
|
|
36
|
-
*/
|
|
37
|
-
struct AVCodecDescriptor
|
|
38
|
-
{
|
|
39
|
-
enum AVCodecID id;
|
|
40
|
-
enum AVMediaType type;
|
|
41
|
-
const char *name, *long_name;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Wrapper around the ffmpeg library that must be loaded at runtime.
|
|
46
|
-
*/
|
|
47
|
-
struct FFMPEG_Library
|
|
48
|
-
{
|
|
49
|
-
void *handle;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L6228
|
|
53
|
-
*
|
|
54
|
-
* We use AVCodecDescriptor because it is the only structure that we can
|
|
55
|
-
* query on all platforms. Windows' ffmpeg.dll does not export a
|
|
56
|
-
* `av_codec_next` function, only `avcodec_descriptor_next`.
|
|
57
|
-
* Also it seems that this "descriptor" concept is the recommended API.
|
|
58
|
-
*/
|
|
59
|
-
struct AVCodecDescriptor *(*avcodec_descriptor_next)(const struct AVCodecDescriptor *);
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L4646
|
|
63
|
-
*/
|
|
64
|
-
struct AVCodec *(*avcodec_find_decoder)(enum AVCodecID);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
#define NULL_FFMPEG_LIBRARY \
|
|
68
|
-
(struct FFMPEG_Library) { NULL, NULL, NULL }
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Loader that will inject the loaded functions into a FFMPEG_Library structure.
|
|
72
|
-
*/
|
|
73
|
-
char *load_ffmpeg_library(struct FFMPEG_Library *library, char *library_path);
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Free library.
|
|
77
|
-
*/
|
|
78
|
-
char *unload_ffmpeg_library(struct FFMPEG_Library *library);
|
|
79
|
-
|
|
80
|
-
#endif // FFMPEG_H guard
|
|
1
|
+
#ifndef FFMPEG_H
|
|
2
|
+
#define FFMPEG_H
|
|
3
|
+
/**
|
|
4
|
+
* THIS FILE REDEFINES DATA AS RETURNED BY THE FFMPEG LIBRARY.
|
|
5
|
+
* HEADER FILES ARE NOT DISTRIBUTED IN OUR SETUP, HENCE THIS.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavutil/avutil.h#L193-L201
|
|
10
|
+
*/
|
|
11
|
+
enum AVMediaType
|
|
12
|
+
{
|
|
13
|
+
_UNKNOWN_DATA_AVMediaType = -1,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L191-L653
|
|
18
|
+
*/
|
|
19
|
+
enum AVCodecID
|
|
20
|
+
{
|
|
21
|
+
__UNKNOWN_DATA_AVCodecID = 0,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L3611-L3721
|
|
26
|
+
*/
|
|
27
|
+
struct AVCodec
|
|
28
|
+
{
|
|
29
|
+
const char *name, *long_name;
|
|
30
|
+
enum AVMediaType type;
|
|
31
|
+
enum AVCodecID id;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L660-L688
|
|
36
|
+
*/
|
|
37
|
+
struct AVCodecDescriptor
|
|
38
|
+
{
|
|
39
|
+
enum AVCodecID id;
|
|
40
|
+
enum AVMediaType type;
|
|
41
|
+
const char *name, *long_name;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Wrapper around the ffmpeg library that must be loaded at runtime.
|
|
46
|
+
*/
|
|
47
|
+
struct FFMPEG_Library
|
|
48
|
+
{
|
|
49
|
+
void *handle;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L6228
|
|
53
|
+
*
|
|
54
|
+
* We use AVCodecDescriptor because it is the only structure that we can
|
|
55
|
+
* query on all platforms. Windows' ffmpeg.dll does not export a
|
|
56
|
+
* `av_codec_next` function, only `avcodec_descriptor_next`.
|
|
57
|
+
* Also it seems that this "descriptor" concept is the recommended API.
|
|
58
|
+
*/
|
|
59
|
+
struct AVCodecDescriptor *(*avcodec_descriptor_next)(const struct AVCodecDescriptor *);
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* https://github.com/FFmpeg/FFmpeg/blob/release/3.2/libavcodec/avcodec.h#L4646
|
|
63
|
+
*/
|
|
64
|
+
struct AVCodec *(*avcodec_find_decoder)(enum AVCodecID);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
#define NULL_FFMPEG_LIBRARY \
|
|
68
|
+
(struct FFMPEG_Library) { NULL, NULL, NULL }
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Loader that will inject the loaded functions into a FFMPEG_Library structure.
|
|
72
|
+
*/
|
|
73
|
+
char *load_ffmpeg_library(struct FFMPEG_Library *library, char *library_path);
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Free library.
|
|
77
|
+
*/
|
|
78
|
+
char *unload_ffmpeg_library(struct FFMPEG_Library *library);
|
|
79
|
+
|
|
80
|
+
#endif // FFMPEG_H guard
|