@scrypted/libav 1.0.4 → 1.0.6
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/darwin.md +24 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +79 -2
- package/lib/index.js.map +1 -1
- package/package.json +1 -2
- package/src/frame.cpp +17 -12
- package/src/index.ts +41 -1
- package/src/tsconfig.json +1 -0
package/darwin.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Mimimum macOS configuration for RTSP, h264, h265, jpg, and videotoolbox.
|
|
2
|
+
|
|
3
|
+
```sh
|
|
4
|
+
./configure \
|
|
5
|
+
--disable-everything \
|
|
6
|
+
--enable-hwaccels \
|
|
7
|
+
--enable-videotoolbox \
|
|
8
|
+
--enable-decoder=h264 \
|
|
9
|
+
--enable-decoder=hevc \
|
|
10
|
+
--enable-demuxer=rtsp \
|
|
11
|
+
--enable-muxer=mjpeg \
|
|
12
|
+
--enable-encoder=mjpeg \
|
|
13
|
+
--enable-parser=mjpeg \
|
|
14
|
+
--enable-protocol=tcp \
|
|
15
|
+
--enable-protocol=udp \
|
|
16
|
+
--enable-filter=crop \
|
|
17
|
+
--enable-filter=scale \
|
|
18
|
+
--enable-filter=scale_vt \
|
|
19
|
+
--enable-filter=format \
|
|
20
|
+
--enable-filter=hwdownload \
|
|
21
|
+
--enable-filter=hwupload \
|
|
22
|
+
--enable-parser=h264 \
|
|
23
|
+
--enable-parser=hevc
|
|
24
|
+
```
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,17 +1,94 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
2
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
42
|
+
exports.isInstalled = isInstalled;
|
|
43
|
+
exports.install = install;
|
|
4
44
|
exports.setAVLogCallback = setAVLogCallback;
|
|
5
45
|
exports.createAVFormatContext = createAVFormatContext;
|
|
46
|
+
var path_1 = __importDefault(require("path"));
|
|
47
|
+
var child_process_1 = require("child_process");
|
|
6
48
|
var addon;
|
|
7
49
|
try {
|
|
8
50
|
addon = require('../build/Release/addon');
|
|
9
51
|
}
|
|
10
52
|
catch (e) {
|
|
11
53
|
}
|
|
12
|
-
function
|
|
54
|
+
function isInstalled() {
|
|
13
55
|
return !!addon;
|
|
14
56
|
}
|
|
57
|
+
var installing;
|
|
58
|
+
function install() {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
60
|
+
return __generator(this, function (_a) {
|
|
61
|
+
if (addon)
|
|
62
|
+
return [2 /*return*/];
|
|
63
|
+
if (installing)
|
|
64
|
+
return [2 /*return*/, installing];
|
|
65
|
+
installing = new Promise(function (resolve, reject) {
|
|
66
|
+
var cp = (0, child_process_1.fork)(require.resolve('prebuild-install/bin.js'), {
|
|
67
|
+
cwd: path_1.default.dirname(__dirname),
|
|
68
|
+
});
|
|
69
|
+
cp.on('error', reject);
|
|
70
|
+
cp.on('exit', function (code) {
|
|
71
|
+
if (code === 0) {
|
|
72
|
+
try {
|
|
73
|
+
addon = require('../build/Release/addon');
|
|
74
|
+
resolve();
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
reject(e);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
reject(new Error('Failed to install'));
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
})
|
|
85
|
+
.finally(function () {
|
|
86
|
+
installing = undefined;
|
|
87
|
+
});
|
|
88
|
+
return [2 /*return*/, installing];
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
15
92
|
function setAVLogCallback(callback) {
|
|
16
93
|
addon.set_console_callback(callback);
|
|
17
94
|
}
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,kCAEC;AAGD,0BAkCC;AA4BD,4CAEC;AAED,sDAEC;AAnFD,8CAAwB;AACxB,+CAAqC;AAErC,IAAI,KAAU,CAAC;AACf,IAAI,CAAC;IACD,KAAK,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;AAC9C,CAAC;AACD,OAAO,CAAC,EAAE,CAAC;AACX,CAAC;AAED,SAAgB,WAAW;IACvB,OAAO,CAAC,CAAC,KAAK,CAAC;AACnB,CAAC;AAED,IAAI,UAAqC,CAAC;AAC1C,SAAsB,OAAO;;;YACzB,IAAI,KAAK;gBACL,sBAAO;YAEX,IAAI,UAAU;gBACV,sBAAO,UAAU,EAAC;YAEtB,UAAU,GAAG,IAAI,OAAO,CAAO,UAAC,OAAO,EAAE,MAAM;gBAC3C,IAAM,EAAE,GAAG,IAAA,oBAAI,EAAC,OAAO,CAAC,OAAO,CAAC,yBAAyB,CAAC,EAAE;oBACxD,GAAG,EAAE,cAAI,CAAC,OAAO,CAAC,SAAS,CAAC;iBAC/B,CAAC,CAAC;gBAEH,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;gBAEvB,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,UAAC,IAAI;oBACf,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;wBACb,IAAI,CAAC;4BACD,KAAK,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;4BAC1C,OAAO,EAAE,CAAC;wBACd,CAAC;wBACD,OAAO,CAAC,EAAE,CAAC;4BACP,MAAM,CAAC,CAAC,CAAC,CAAC;wBACd,CAAC;oBACL,CAAC;yBACI,CAAC;wBACF,MAAM,CAAC,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC;oBAC3C,CAAC;gBACL,CAAC,CAAC,CAAC;YACP,CAAC,CAAC;iBACD,OAAO,CAAC;gBACL,UAAU,GAAG,SAAS,CAAC;YAC3B,CAAC,CAAC,CAAC;YAEH,sBAAO,UAAU,EAAC;;;CACrB;AA4BD,SAAgB,gBAAgB,CAAC,QAA+B;IAC5D,KAAK,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;AACzC,CAAC;AAED,SAAgB,qBAAqB;IACjC,OAAO,IAAI,KAAK,CAAC,eAAe,EAAE,CAAC;AACvC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scrypted/libav",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"node-addon-api": "^8.1.0",
|
|
6
6
|
"prebuild-install": "npm:@scrypted/prebuild-install@^7.1.8"
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
"node-gyp-build": "node-gyp build",
|
|
27
27
|
"node-gyp-rebuild": "node-gyp rebuild",
|
|
28
28
|
"build": "tsc -b ./src/tsconfig.json",
|
|
29
|
-
"install": "prebuild-install || npm run node-gyp-rebuild",
|
|
30
29
|
"prepare": "npm run build",
|
|
31
30
|
"release": "npm version patch && npm publish --access public && git push --tags",
|
|
32
31
|
"prepublishOnly": "npm run build"
|
package/src/frame.cpp
CHANGED
|
@@ -127,9 +127,9 @@ Napi::Value AVFrameObject::ToJPEG(const Napi::CallbackInfo &info)
|
|
|
127
127
|
|
|
128
128
|
// Set the JPEG quality
|
|
129
129
|
int quality = info[0].As<Napi::Number>().Int32Value(); // 1-31, lower is better quality
|
|
130
|
-
av_opt_set_int(c, "qscale", quality, 0);
|
|
131
|
-
av_opt_set_int(c, "qmin", quality, 0);
|
|
132
|
-
av_opt_set_int(c, "qmax", quality, 0);
|
|
130
|
+
av_opt_set_int(c, "qscale", quality, 0); // Set the quality scale (1-31, lower is better quality)
|
|
131
|
+
av_opt_set_int(c, "qmin", quality, 0); // Set the minimum quality
|
|
132
|
+
av_opt_set_int(c, "qmax", quality, 0); // Set the maximum quality
|
|
133
133
|
|
|
134
134
|
if (avcodec_open2(c, codec, NULL) < 0)
|
|
135
135
|
{
|
|
@@ -159,7 +159,7 @@ Napi::Value AVFrameObject::ToJPEG(const Napi::CallbackInfo &info)
|
|
|
159
159
|
return env.Null();
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
Napi::Buffer<uint8_t> buffer = Napi::Buffer<uint8_t>::
|
|
162
|
+
Napi::Buffer<uint8_t> buffer = Napi::Buffer<uint8_t>::Copy(env, pkt.data, pkt.size);
|
|
163
163
|
av_packet_unref(&pkt);
|
|
164
164
|
avcodec_free_context(&c);
|
|
165
165
|
|
|
@@ -180,22 +180,27 @@ Napi::Value AVFrameObject::ToBuffer(const Napi::CallbackInfo &info)
|
|
|
180
180
|
int height = frame_->height;
|
|
181
181
|
int buffer_size = av_image_get_buffer_size((enum AVPixelFormat)frame_->format, width, height, 1);
|
|
182
182
|
|
|
183
|
-
|
|
184
|
-
|
|
183
|
+
Napi::Buffer<uint8_t> buffer = Napi::Buffer<uint8_t>::New(env, buffer_size);
|
|
184
|
+
|
|
185
|
+
uint8_t *byte_array = buffer.Data();
|
|
185
186
|
if (!byte_array)
|
|
186
187
|
{
|
|
187
188
|
Napi::Error::New(env, "Failed to allocate memory for byte array").ThrowAsJavaScriptException();
|
|
188
189
|
return env.Null();
|
|
189
190
|
}
|
|
190
191
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
for (int y = 0; y < height; y++)
|
|
192
|
+
int frame_size = frame_->linesize[0] * height;
|
|
193
|
+
if (frame_size != buffer_size)
|
|
194
194
|
{
|
|
195
|
-
|
|
195
|
+
int stride = buffer_size / height;
|
|
196
|
+
for (int y = 0; y < height; y++)
|
|
197
|
+
{
|
|
198
|
+
memcpy(byte_array + y * stride, frame_->data[0] + y * frame_->linesize[0], stride);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
memcpy(byte_array, frame_->data[0], buffer_size);
|
|
196
203
|
}
|
|
197
|
-
|
|
198
|
-
Napi::Buffer<uint8_t> buffer = Napi::Buffer<uint8_t>::New(env, byte_array, buffer_size);
|
|
199
204
|
|
|
200
205
|
return buffer;
|
|
201
206
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { fork } from 'child_process';
|
|
3
|
+
|
|
1
4
|
let addon: any;
|
|
2
5
|
try {
|
|
3
6
|
addon = require('../build/Release/addon');
|
|
@@ -5,10 +8,47 @@ try {
|
|
|
5
8
|
catch (e) {
|
|
6
9
|
}
|
|
7
10
|
|
|
8
|
-
export function
|
|
11
|
+
export function isInstalled() {
|
|
9
12
|
return !!addon;
|
|
10
13
|
}
|
|
11
14
|
|
|
15
|
+
let installing: Promise<void> | undefined;
|
|
16
|
+
export async function install() {
|
|
17
|
+
if (addon)
|
|
18
|
+
return;
|
|
19
|
+
|
|
20
|
+
if (installing)
|
|
21
|
+
return installing;
|
|
22
|
+
|
|
23
|
+
installing = new Promise<void>((resolve, reject) => {
|
|
24
|
+
const cp = fork(require.resolve('prebuild-install/bin.js'), {
|
|
25
|
+
cwd: path.dirname(__dirname),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
cp.on('error', reject);
|
|
29
|
+
|
|
30
|
+
cp.on('exit', (code) => {
|
|
31
|
+
if (code === 0) {
|
|
32
|
+
try {
|
|
33
|
+
addon = require('../build/Release/addon');
|
|
34
|
+
resolve();
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
reject(e);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
reject(new Error('Failed to install'));
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
})
|
|
45
|
+
.finally(() => {
|
|
46
|
+
installing = undefined;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return installing;
|
|
50
|
+
}
|
|
51
|
+
|
|
12
52
|
export interface AVFrame {
|
|
13
53
|
close(): void;
|
|
14
54
|
width: number;
|