@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/native/linux-ffmpeg.c
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
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
|
-
#ifndef LINUX_FFMPEG
|
|
18
|
-
#define LINUX_FFMPEG
|
|
19
|
-
|
|
20
|
-
#include <stdlib.h>
|
|
21
|
-
#include <dlfcn.h>
|
|
22
|
-
|
|
23
|
-
#include "ffmpeg.h"
|
|
24
|
-
|
|
25
|
-
char *load_ffmpeg_library(struct FFMPEG_Library *library, char *library_path)
|
|
26
|
-
{
|
|
27
|
-
void *handle = dlopen(library_path, RTLD_NOW);
|
|
28
|
-
char *error = dlerror();
|
|
29
|
-
if (error != NULL)
|
|
30
|
-
{
|
|
31
|
-
goto error;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
struct AVCodecDescriptor *(*avcodec_descriptor_next)(const struct AVCodecDescriptor *) = dlsym(handle, "avcodec_descriptor_next");
|
|
35
|
-
error = dlerror();
|
|
36
|
-
if (error != NULL)
|
|
37
|
-
{
|
|
38
|
-
goto error;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
struct AVCodec *(*avcodec_find_decoder)(enum AVCodecID) = dlsym(handle, "avcodec_find_decoder");
|
|
42
|
-
error = dlerror();
|
|
43
|
-
if (error != NULL)
|
|
44
|
-
{
|
|
45
|
-
goto error;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
library->handle = handle;
|
|
49
|
-
library->avcodec_descriptor_next = avcodec_descriptor_next;
|
|
50
|
-
library->avcodec_find_decoder = avcodec_find_decoder;
|
|
51
|
-
return NULL;
|
|
52
|
-
|
|
53
|
-
error:
|
|
54
|
-
if (handle != NULL)
|
|
55
|
-
{
|
|
56
|
-
dlclose(handle);
|
|
57
|
-
}
|
|
58
|
-
return error;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
char *unload_ffmpeg_library(struct FFMPEG_Library *library)
|
|
62
|
-
{
|
|
63
|
-
dlclose(library->handle);
|
|
64
|
-
*library = NULL_FFMPEG_LIBRARY;
|
|
65
|
-
return dlerror();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
#endif // LINUX_FFMPEG guard
|
|
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
|
+
#ifndef LINUX_FFMPEG
|
|
18
|
+
#define LINUX_FFMPEG
|
|
19
|
+
|
|
20
|
+
#include <stdlib.h>
|
|
21
|
+
#include <dlfcn.h>
|
|
22
|
+
|
|
23
|
+
#include "ffmpeg.h"
|
|
24
|
+
|
|
25
|
+
char *load_ffmpeg_library(struct FFMPEG_Library *library, char *library_path)
|
|
26
|
+
{
|
|
27
|
+
void *handle = dlopen(library_path, RTLD_NOW);
|
|
28
|
+
char *error = dlerror();
|
|
29
|
+
if (error != NULL)
|
|
30
|
+
{
|
|
31
|
+
goto error;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
struct AVCodecDescriptor *(*avcodec_descriptor_next)(const struct AVCodecDescriptor *) = dlsym(handle, "avcodec_descriptor_next");
|
|
35
|
+
error = dlerror();
|
|
36
|
+
if (error != NULL)
|
|
37
|
+
{
|
|
38
|
+
goto error;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
struct AVCodec *(*avcodec_find_decoder)(enum AVCodecID) = dlsym(handle, "avcodec_find_decoder");
|
|
42
|
+
error = dlerror();
|
|
43
|
+
if (error != NULL)
|
|
44
|
+
{
|
|
45
|
+
goto error;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
library->handle = handle;
|
|
49
|
+
library->avcodec_descriptor_next = avcodec_descriptor_next;
|
|
50
|
+
library->avcodec_find_decoder = avcodec_find_decoder;
|
|
51
|
+
return NULL;
|
|
52
|
+
|
|
53
|
+
error:
|
|
54
|
+
if (handle != NULL)
|
|
55
|
+
{
|
|
56
|
+
dlclose(handle);
|
|
57
|
+
}
|
|
58
|
+
return error;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
char *unload_ffmpeg_library(struct FFMPEG_Library *library)
|
|
62
|
+
{
|
|
63
|
+
dlclose(library->handle);
|
|
64
|
+
*library = NULL_FFMPEG_LIBRARY;
|
|
65
|
+
return dlerror();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
#endif // LINUX_FFMPEG guard
|
package/native/mac-ffmpeg.c
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
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
|
-
#ifndef MAC_FFMPEG
|
|
18
|
-
#define MAC_FFMPEG
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Mac seems to use the same libraries as Linux.
|
|
22
|
-
* Difference is that the compiler doesn't need to be told to use `-ldl`.
|
|
23
|
-
*/
|
|
24
|
-
#include "./linux-ffmpeg.c"
|
|
25
|
-
|
|
26
|
-
#endif // MAC_FFMPEG guard
|
|
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
|
+
#ifndef MAC_FFMPEG
|
|
18
|
+
#define MAC_FFMPEG
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Mac seems to use the same libraries as Linux.
|
|
22
|
+
* Difference is that the compiler doesn't need to be told to use `-ldl`.
|
|
23
|
+
*/
|
|
24
|
+
#include "./linux-ffmpeg.c"
|
|
25
|
+
|
|
26
|
+
#endif // MAC_FFMPEG guard
|
package/native/win-ffmpeg.c
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
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
|
-
#ifndef WIN_FFMPEG
|
|
17
|
-
#define WIN_FFMPEG
|
|
18
|
-
|
|
19
|
-
#include <windows.h>
|
|
20
|
-
|
|
21
|
-
#include "ffmpeg.h"
|
|
22
|
-
|
|
23
|
-
static char *error_library_not_found = "shared library not found";
|
|
24
|
-
static char *error_function_not_found = "function not found in shared library";
|
|
25
|
-
static char *error_cannot_free_library = "cannot free shared library";
|
|
26
|
-
|
|
27
|
-
char *load_ffmpeg_library(struct FFMPEG_Library *library, char *library_path)
|
|
28
|
-
{
|
|
29
|
-
char *error = NULL;
|
|
30
|
-
|
|
31
|
-
HMODULE handle = LoadLibrary(library_path);
|
|
32
|
-
if (!handle)
|
|
33
|
-
{
|
|
34
|
-
error = error_library_not_found;
|
|
35
|
-
goto error;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
struct AVCodecDescriptor *(*av_codec_next)(const struct AVCodecDescriptor *) = (struct AVCodecDescriptor * (*)(const struct AVCodecDescriptor *))
|
|
39
|
-
GetProcAddress(handle, "avcodec_descriptor_next");
|
|
40
|
-
if (!av_codec_next)
|
|
41
|
-
{
|
|
42
|
-
error = error_function_not_found;
|
|
43
|
-
goto error;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
struct AVCodec *(*avcodec_find_decoder)(enum AVCodecID) = (struct AVCodec * (*)(enum AVCodecID))
|
|
47
|
-
GetProcAddress(handle, "avcodec_find_decoder");
|
|
48
|
-
if (!avcodec_find_decoder)
|
|
49
|
-
{
|
|
50
|
-
error = error_function_not_found;
|
|
51
|
-
goto error;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
library->handle = handle;
|
|
55
|
-
library->avcodec_descriptor_next = av_codec_next;
|
|
56
|
-
library->avcodec_find_decoder = avcodec_find_decoder;
|
|
57
|
-
return NULL;
|
|
58
|
-
|
|
59
|
-
error:
|
|
60
|
-
if (handle)
|
|
61
|
-
{
|
|
62
|
-
FreeLibrary(handle);
|
|
63
|
-
}
|
|
64
|
-
return error;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
char *unload_ffmpeg_library(struct FFMPEG_Library *library)
|
|
68
|
-
{
|
|
69
|
-
if (library->handle && FreeLibrary(library->handle))
|
|
70
|
-
{
|
|
71
|
-
*library = NULL_FFMPEG_LIBRARY;
|
|
72
|
-
return NULL;
|
|
73
|
-
}
|
|
74
|
-
return error_cannot_free_library;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
#endif // WIN_FFMPEG guard
|
|
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
|
+
#ifndef WIN_FFMPEG
|
|
17
|
+
#define WIN_FFMPEG
|
|
18
|
+
|
|
19
|
+
#include <windows.h>
|
|
20
|
+
|
|
21
|
+
#include "ffmpeg.h"
|
|
22
|
+
|
|
23
|
+
static char *error_library_not_found = "shared library not found";
|
|
24
|
+
static char *error_function_not_found = "function not found in shared library";
|
|
25
|
+
static char *error_cannot_free_library = "cannot free shared library";
|
|
26
|
+
|
|
27
|
+
char *load_ffmpeg_library(struct FFMPEG_Library *library, char *library_path)
|
|
28
|
+
{
|
|
29
|
+
char *error = NULL;
|
|
30
|
+
|
|
31
|
+
HMODULE handle = LoadLibrary(library_path);
|
|
32
|
+
if (!handle)
|
|
33
|
+
{
|
|
34
|
+
error = error_library_not_found;
|
|
35
|
+
goto error;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
struct AVCodecDescriptor *(*av_codec_next)(const struct AVCodecDescriptor *) = (struct AVCodecDescriptor * (*)(const struct AVCodecDescriptor *))
|
|
39
|
+
GetProcAddress(handle, "avcodec_descriptor_next");
|
|
40
|
+
if (!av_codec_next)
|
|
41
|
+
{
|
|
42
|
+
error = error_function_not_found;
|
|
43
|
+
goto error;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
struct AVCodec *(*avcodec_find_decoder)(enum AVCodecID) = (struct AVCodec * (*)(enum AVCodecID))
|
|
47
|
+
GetProcAddress(handle, "avcodec_find_decoder");
|
|
48
|
+
if (!avcodec_find_decoder)
|
|
49
|
+
{
|
|
50
|
+
error = error_function_not_found;
|
|
51
|
+
goto error;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
library->handle = handle;
|
|
55
|
+
library->avcodec_descriptor_next = av_codec_next;
|
|
56
|
+
library->avcodec_find_decoder = avcodec_find_decoder;
|
|
57
|
+
return NULL;
|
|
58
|
+
|
|
59
|
+
error:
|
|
60
|
+
if (handle)
|
|
61
|
+
{
|
|
62
|
+
FreeLibrary(handle);
|
|
63
|
+
}
|
|
64
|
+
return error;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
char *unload_ffmpeg_library(struct FFMPEG_Library *library)
|
|
68
|
+
{
|
|
69
|
+
if (library->handle && FreeLibrary(library->handle))
|
|
70
|
+
{
|
|
71
|
+
*library = NULL_FFMPEG_LIBRARY;
|
|
72
|
+
return NULL;
|
|
73
|
+
}
|
|
74
|
+
return error_cannot_free_library;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
#endif // WIN_FFMPEG guard
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theia/ffmpeg",
|
|
3
|
-
"version": "1.48.
|
|
3
|
+
"version": "1.48.1",
|
|
4
4
|
"description": "Theia FFMPEG reader utility.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/unzipper": "^0.9.2"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "04c631933dfd14f58d1df5b9b28dd5596c84ec04"
|
|
39
39
|
}
|
package/src/check-ffmpeg.ts
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
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 * as ffmpeg from './ffmpeg';
|
|
18
|
-
|
|
19
|
-
export interface CheckFfmpegOptions extends ffmpeg.FfmpegOptions {
|
|
20
|
-
json?: boolean
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface CheckFfmpegResult {
|
|
24
|
-
free: ffmpeg.Codec[],
|
|
25
|
-
proprietary: ffmpeg.Codec[],
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const KNOWN_PROPRIETARY_CODECS = new Set(['h264', 'aac']);
|
|
29
|
-
|
|
30
|
-
export async function checkFfmpeg(options: CheckFfmpegOptions = {}): Promise<void> {
|
|
31
|
-
const {
|
|
32
|
-
ffmpegPath = ffmpeg.ffmpegAbsolutePath(options),
|
|
33
|
-
json = false,
|
|
34
|
-
} = options;
|
|
35
|
-
const codecs = ffmpeg.getFfmpegCodecs(ffmpegPath);
|
|
36
|
-
const free = [];
|
|
37
|
-
const proprietary = [];
|
|
38
|
-
for (const codec of codecs) {
|
|
39
|
-
if (KNOWN_PROPRIETARY_CODECS.has(codec.name.toLowerCase())) {
|
|
40
|
-
proprietary.push(codec);
|
|
41
|
-
} else {
|
|
42
|
-
free.push(codec);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (json) {
|
|
46
|
-
// Pretty format JSON on stdout.
|
|
47
|
-
const result: CheckFfmpegResult = { free, proprietary };
|
|
48
|
-
console.log(JSON.stringify(result, undefined, 2));
|
|
49
|
-
}
|
|
50
|
-
if (proprietary.length > 0) {
|
|
51
|
-
// Should be displayed on stderr to not pollute the JSON on stdout.
|
|
52
|
-
throw new Error(`${proprietary.length} proprietary codecs found\n${proprietary.map(codec => `> ${codec.name} detected (${codec.longName})`).join('\n')}`);
|
|
53
|
-
}
|
|
54
|
-
// Print to stderr to not pollute the JSON on stdout.
|
|
55
|
-
console.warn(`"${ffmpegPath}" does not contain proprietary codecs (${codecs.length} found).`);
|
|
56
|
-
}
|
|
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 * as ffmpeg from './ffmpeg';
|
|
18
|
+
|
|
19
|
+
export interface CheckFfmpegOptions extends ffmpeg.FfmpegOptions {
|
|
20
|
+
json?: boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface CheckFfmpegResult {
|
|
24
|
+
free: ffmpeg.Codec[],
|
|
25
|
+
proprietary: ffmpeg.Codec[],
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const KNOWN_PROPRIETARY_CODECS = new Set(['h264', 'aac']);
|
|
29
|
+
|
|
30
|
+
export async function checkFfmpeg(options: CheckFfmpegOptions = {}): Promise<void> {
|
|
31
|
+
const {
|
|
32
|
+
ffmpegPath = ffmpeg.ffmpegAbsolutePath(options),
|
|
33
|
+
json = false,
|
|
34
|
+
} = options;
|
|
35
|
+
const codecs = ffmpeg.getFfmpegCodecs(ffmpegPath);
|
|
36
|
+
const free = [];
|
|
37
|
+
const proprietary = [];
|
|
38
|
+
for (const codec of codecs) {
|
|
39
|
+
if (KNOWN_PROPRIETARY_CODECS.has(codec.name.toLowerCase())) {
|
|
40
|
+
proprietary.push(codec);
|
|
41
|
+
} else {
|
|
42
|
+
free.push(codec);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (json) {
|
|
46
|
+
// Pretty format JSON on stdout.
|
|
47
|
+
const result: CheckFfmpegResult = { free, proprietary };
|
|
48
|
+
console.log(JSON.stringify(result, undefined, 2));
|
|
49
|
+
}
|
|
50
|
+
if (proprietary.length > 0) {
|
|
51
|
+
// Should be displayed on stderr to not pollute the JSON on stdout.
|
|
52
|
+
throw new Error(`${proprietary.length} proprietary codecs found\n${proprietary.map(codec => `> ${codec.name} detected (${codec.longName})`).join('\n')}`);
|
|
53
|
+
}
|
|
54
|
+
// Print to stderr to not pollute the JSON on stdout.
|
|
55
|
+
console.warn(`"${ffmpegPath}" does not contain proprietary codecs (${codecs.length} found).`);
|
|
56
|
+
}
|