iobroker.eusec 1.1.0 → 1.1.2

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.
@@ -1,272 +1,257 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
4
11
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ffmpegStreamToGo2rtc = exports.ffmpegStreamToHls = exports.ffmpegPreviewImage = exports.StreamOutput = exports.StreamInput = void 0;
7
- const net_1 = __importDefault(require("net"));
8
- const path_1 = __importDefault(require("path"));
9
- const fluent_ffmpeg_1 = __importDefault(require("@bropat/fluent-ffmpeg"));
10
- const ffmpeg_static_1 = __importDefault(require("ffmpeg-static"));
11
- const eufy_security_client_1 = require("eufy-security-client");
12
- const os_1 = require("os");
13
- const fs_extra_1 = __importDefault(require("fs-extra"));
14
- const utils_1 = require("./utils");
15
- class UniversalStream {
16
- constructor(namespace, onSocket) {
17
- let sockpath = "";
18
- const unique_sock_id = (0, utils_1.lowestUnusedNumber)([...UniversalStream.socks], 1);
19
- UniversalStream.socks.add(unique_sock_id);
20
- this.sock_id = unique_sock_id;
21
- if (process.platform === "win32") {
22
- const pipePrefix = "\\\\.\\pipe\\";
23
- const pipeName = `node-webrtc.${namespace}.${unique_sock_id}.sock`;
24
- sockpath = path_1.default.join(pipePrefix, pipeName);
25
- this.url = sockpath;
26
- }
27
- else {
28
- const pipeName = `${namespace}.${unique_sock_id}.sock`;
29
- sockpath = path_1.default.join((0, os_1.tmpdir)(), pipeName);
30
- this.url = "unix:" + sockpath;
31
- try {
32
- if (fs_extra_1.default.existsSync(sockpath))
33
- fs_extra_1.default.unlinkSync(sockpath);
34
- }
35
- catch (error) {
36
- }
37
- }
38
- this.server = net_1.default.createServer(onSocket);
39
- this.server.listen(sockpath);
40
- }
41
- close() {
42
- if (this.server)
43
- this.server.close();
44
- UniversalStream.socks.delete(this.sock_id);
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var video_exports = {};
26
+ __export(video_exports, {
27
+ StreamInput: () => StreamInput,
28
+ StreamOutput: () => StreamOutput,
29
+ ffmpegPreviewImage: () => ffmpegPreviewImage,
30
+ ffmpegStreamToGo2rtc: () => ffmpegStreamToGo2rtc,
31
+ ffmpegStreamToHls: () => ffmpegStreamToHls
32
+ });
33
+ module.exports = __toCommonJS(video_exports);
34
+ var import_net = __toESM(require("net"));
35
+ var import_path = __toESM(require("path"));
36
+ var import_fluent_ffmpeg = __toESM(require("@bropat/fluent-ffmpeg"));
37
+ var import_ffmpeg_static = __toESM(require("ffmpeg-static"));
38
+ var import_eufy_security_client = require("eufy-security-client");
39
+ var import_os = require("os");
40
+ var import_fs_extra = __toESM(require("fs-extra"));
41
+ var import_utils = require("./utils");
42
+ const _UniversalStream = class {
43
+ constructor(namespace, onSocket) {
44
+ let sockpath = "";
45
+ const unique_sock_id = (0, import_utils.lowestUnusedNumber)([..._UniversalStream.socks], 1);
46
+ _UniversalStream.socks.add(unique_sock_id);
47
+ this.sock_id = unique_sock_id;
48
+ if (process.platform === "win32") {
49
+ const pipePrefix = "\\\\.\\pipe\\";
50
+ const pipeName = `node-webrtc.${namespace}.${unique_sock_id}.sock`;
51
+ sockpath = import_path.default.join(pipePrefix, pipeName);
52
+ this.url = sockpath;
53
+ } else {
54
+ const pipeName = `${namespace}.${unique_sock_id}.sock`;
55
+ sockpath = import_path.default.join((0, import_os.tmpdir)(), pipeName);
56
+ this.url = "unix:" + sockpath;
57
+ try {
58
+ if (import_fs_extra.default.existsSync(sockpath))
59
+ import_fs_extra.default.unlinkSync(sockpath);
60
+ } catch (error) {
61
+ }
45
62
  }
46
- }
47
- UniversalStream.socks = new Set();
48
- const StreamInput = function (namespace, stream) {
49
- return new UniversalStream(namespace, (socket) => stream.pipe(socket, { end: true }));
63
+ this.server = import_net.default.createServer(onSocket);
64
+ this.server.listen(sockpath);
65
+ }
66
+ close() {
67
+ if (this.server)
68
+ this.server.close();
69
+ _UniversalStream.socks.delete(this.sock_id);
70
+ }
50
71
  };
51
- exports.StreamInput = StreamInput;
52
- const StreamOutput = function (namespace, stream) {
53
- return new UniversalStream(namespace, (socket) => socket.pipe(stream, { end: true }));
72
+ let UniversalStream = _UniversalStream;
73
+ UniversalStream.socks = /* @__PURE__ */ new Set();
74
+ const StreamInput = function(namespace, stream) {
75
+ return new UniversalStream(namespace, (socket) => stream.pipe(socket, { end: true }));
54
76
  };
55
- exports.StreamOutput = StreamOutput;
56
- const ffmpegPreviewImage = (config, input, output, log, skip_seconds = 2.0) => {
57
- return new Promise((resolve, reject) => {
58
- try {
59
- if (ffmpeg_static_1.default) {
60
- fluent_ffmpeg_1.default.setFfmpegPath(ffmpeg_static_1.default);
61
- (0, fluent_ffmpeg_1.default)()
62
- .withProcessOptions({
63
- detached: true
64
- })
65
- .addOptions([
66
- `-ss ${skip_seconds}`,
67
- "-frames:v 1"
68
- ])
69
- .input(input)
70
- .inputFormat("hls")
71
- .outputFormat("image2")
72
- .output(output)
73
- .on("error", function (err, stdout, stderr) {
74
- log.error(`ffmpegPreviewImage(): An error occurred: ${err.message}`);
75
- log.error(`ffmpegPreviewImage(): ffmpeg output:\n${stdout}`);
76
- log.error(`ffmpegPreviewImage(): ffmpeg stderr:\n${stderr}`);
77
- reject(err);
78
- })
79
- .on("end", () => {
80
- log.debug("ffmpegPreviewImage(): Preview image generated!");
81
- resolve();
82
- })
83
- .run();
84
- }
85
- else {
86
- reject(new Error("ffmpeg binary not found"));
87
- }
88
- }
89
- catch (error) {
90
- log.error(`ffmpegPreviewImage(): Error: ${error}`);
91
- reject(error);
92
- }
93
- });
77
+ const StreamOutput = function(namespace, stream) {
78
+ return new UniversalStream(namespace, (socket) => socket.pipe(stream, { end: true }));
79
+ };
80
+ const ffmpegPreviewImage = (config, input, output, log, skip_seconds = 2) => {
81
+ return new Promise((resolve, reject) => {
82
+ try {
83
+ if (import_ffmpeg_static.default) {
84
+ import_fluent_ffmpeg.default.setFfmpegPath(import_ffmpeg_static.default);
85
+ (0, import_fluent_ffmpeg.default)().withProcessOptions({
86
+ detached: true
87
+ }).addOptions([
88
+ `-ss ${skip_seconds}`,
89
+ "-frames:v 1"
90
+ ]).input(input).inputFormat("hls").outputFormat("image2").output(output).on("error", function(err, stdout, stderr) {
91
+ log.error(`ffmpegPreviewImage(): An error occurred: ${err.message}`);
92
+ log.error(`ffmpegPreviewImage(): ffmpeg output:
93
+ ${stdout}`);
94
+ log.error(`ffmpegPreviewImage(): ffmpeg stderr:
95
+ ${stderr}`);
96
+ reject(err);
97
+ }).on("end", () => {
98
+ log.debug("ffmpegPreviewImage(): Preview image generated!");
99
+ resolve();
100
+ }).run();
101
+ } else {
102
+ reject(new Error("ffmpeg binary not found"));
103
+ }
104
+ } catch (error) {
105
+ log.error(`ffmpegPreviewImage(): Error: ${error}`);
106
+ reject(error);
107
+ }
108
+ });
94
109
  };
95
- exports.ffmpegPreviewImage = ffmpegPreviewImage;
96
110
  const ffmpegStreamToHls = (config, namespace, metadata, videoStream, audioStream, output, log) => {
97
- return new Promise((resolve, reject) => {
98
- try {
99
- if (ffmpeg_static_1.default) {
100
- fluent_ffmpeg_1.default.setFfmpegPath(ffmpeg_static_1.default);
101
- videoStream.on("error", (error) => {
102
- log.error("ffmpegStreamToHls(): Videostream Error", error);
103
- });
104
- audioStream.on("error", (error) => {
105
- log.error("ffmpegStreamToHls(): Audiostream Error", error);
106
- });
107
- const uVideoStream = (0, exports.StreamInput)(namespace, videoStream);
108
- const uAudioStream = (0, exports.StreamInput)(namespace, audioStream);
109
- let videoFormat = "h264";
110
- let audioFormat = "";
111
- const options = [
112
- "-hls_init_time 0",
113
- "-hls_time 2",
114
- "-hls_segment_type mpegts",
115
- //"-start_number 1",
116
- "-sc_threshold 0",
117
- `-g ${metadata.videoFPS}`,
118
- "-fflags genpts+nobuffer+flush_packets",
119
- //"-flush_packets 1",
120
- "-hls_playlist_type event"
121
- //"-hls_flags split_by_time"
122
- ];
123
- switch (metadata.videoCodec) {
124
- case eufy_security_client_1.VideoCodec.H264:
125
- videoFormat = "h264";
126
- break;
127
- case eufy_security_client_1.VideoCodec.H265:
128
- videoFormat = "hevc";
129
- break;
130
- }
131
- switch (metadata.audioCodec) {
132
- case eufy_security_client_1.AudioCodec.AAC:
133
- audioFormat = "aac";
134
- break;
135
- }
136
- const command = (0, fluent_ffmpeg_1.default)()
137
- .withProcessOptions({
138
- detached: true
139
- })
140
- .input(uVideoStream.url)
141
- .inputFormat(videoFormat)
142
- .inputFps(metadata.videoFPS);
143
- if (audioFormat !== "") {
144
- command.input(uAudioStream.url)
145
- .inputFormat(audioFormat)
146
- .videoCodec("copy")
147
- .audioCodec("copy");
148
- options.push("-absf aac_adtstoasc");
149
- }
150
- else {
151
- log.warn(`ffmpegStreamToHls(): Not support audio codec or unknown audio codec (${eufy_security_client_1.AudioCodec[metadata.audioCodec]})`);
152
- }
153
- command.output(output)
154
- .addOptions(options)
155
- .on("error", function (err, stdout, stderr) {
156
- log.error(`ffmpegStreamToHls(): An error occurred: ${err.message}`);
157
- log.error(`ffmpegStreamToHls(): ffmpeg output:\n${stdout}`);
158
- log.error(`ffmpegStreamToHls(): ffmpeg stderr:\n${stderr}`);
159
- uVideoStream.close();
160
- uAudioStream.close();
161
- reject(err);
162
- })
163
- .on("end", () => {
164
- log.debug("ffmpegStreamToHls(): Processing finished!");
165
- uVideoStream.close();
166
- uAudioStream.close();
167
- resolve();
168
- });
169
- command.run();
170
- }
171
- else {
172
- reject(new Error("ffmpeg binary not found"));
173
- }
111
+ return new Promise((resolve, reject) => {
112
+ try {
113
+ if (import_ffmpeg_static.default) {
114
+ import_fluent_ffmpeg.default.setFfmpegPath(import_ffmpeg_static.default);
115
+ videoStream.on("error", (error) => {
116
+ log.error("ffmpegStreamToHls(): Videostream Error", error);
117
+ });
118
+ audioStream.on("error", (error) => {
119
+ log.error("ffmpegStreamToHls(): Audiostream Error", error);
120
+ });
121
+ const uVideoStream = StreamInput(namespace, videoStream);
122
+ const uAudioStream = StreamInput(namespace, audioStream);
123
+ let videoFormat = "h264";
124
+ let audioFormat = "";
125
+ const options = [
126
+ "-hls_init_time 0",
127
+ "-hls_time 2",
128
+ "-hls_segment_type mpegts",
129
+ "-sc_threshold 0",
130
+ `-g ${metadata.videoFPS}`,
131
+ "-fflags genpts+nobuffer+flush_packets",
132
+ "-hls_playlist_type event"
133
+ ];
134
+ switch (metadata.videoCodec) {
135
+ case import_eufy_security_client.VideoCodec.H264:
136
+ videoFormat = "h264";
137
+ break;
138
+ case import_eufy_security_client.VideoCodec.H265:
139
+ videoFormat = "hevc";
140
+ break;
141
+ }
142
+ switch (metadata.audioCodec) {
143
+ case import_eufy_security_client.AudioCodec.AAC:
144
+ audioFormat = "aac";
145
+ break;
174
146
  }
175
- catch (error) {
176
- log.error(`ffmpegStreamToHls(): Error: ${error}`);
177
- reject(error);
147
+ const command = (0, import_fluent_ffmpeg.default)().withProcessOptions({
148
+ detached: true
149
+ }).input(uVideoStream.url).inputFormat(videoFormat).inputFps(metadata.videoFPS);
150
+ if (audioFormat !== "") {
151
+ command.input(uAudioStream.url).inputFormat(audioFormat).videoCodec("copy").audioCodec("copy");
152
+ options.push("-absf aac_adtstoasc");
153
+ } else {
154
+ log.warn(`ffmpegStreamToHls(): Not support audio codec or unknown audio codec (${import_eufy_security_client.AudioCodec[metadata.audioCodec]})`);
178
155
  }
179
- });
156
+ command.output(output).addOptions(options).on("error", function(err, stdout, stderr) {
157
+ log.error(`ffmpegStreamToHls(): An error occurred: ${err.message}`);
158
+ log.error(`ffmpegStreamToHls(): ffmpeg output:
159
+ ${stdout}`);
160
+ log.error(`ffmpegStreamToHls(): ffmpeg stderr:
161
+ ${stderr}`);
162
+ uVideoStream.close();
163
+ uAudioStream.close();
164
+ reject(err);
165
+ }).on("end", () => {
166
+ log.debug("ffmpegStreamToHls(): Processing finished!");
167
+ uVideoStream.close();
168
+ uAudioStream.close();
169
+ resolve();
170
+ });
171
+ command.run();
172
+ } else {
173
+ reject(new Error("ffmpeg binary not found"));
174
+ }
175
+ } catch (error) {
176
+ log.error(`ffmpegStreamToHls(): Error: ${error}`);
177
+ reject(error);
178
+ }
179
+ });
180
180
  };
181
- exports.ffmpegStreamToHls = ffmpegStreamToHls;
182
181
  const ffmpegStreamToGo2rtc = (config, namespace, camera, metadata, videoStream, audioStream, log) => {
183
- return new Promise((resolve, reject) => {
184
- try {
185
- if (ffmpeg_static_1.default) {
186
- fluent_ffmpeg_1.default.setFfmpegPath(ffmpeg_static_1.default);
187
- log.warn("ffmpegStreamToGo2rtc(): Started");
188
- videoStream.on("error", (error) => {
189
- log.error("ffmpegStreamToGo2rtc(): Videostream Error", error);
190
- });
191
- audioStream.on("error", (error) => {
192
- log.error("ffmpegStreamToGo2rtc(): Audiostream Error", error);
193
- });
194
- //TODO: For debugging purposes
195
- /*const outputFile = path.resolve(__dirname, "../../test-stream.dump");
196
- videoStream.pipe(fse.createWriteStream(outputFile)).on("finish", () => {
197
- log.debug("videoStream dump finished!");
198
- log.info("Manually test the output by running# ffplay output/test-stream.dump");
199
- });*/
200
- const uVideoStream = (0, exports.StreamInput)(namespace, videoStream);
201
- const uAudioStream = (0, exports.StreamInput)(namespace, audioStream);
202
- let videoFormat = "h264";
203
- let audioFormat = "";
204
- const options = [
205
- "-rtsp_transport tcp",
206
- "-sc_threshold 0",
207
- `-g ${metadata.videoFPS}`,
208
- "-fflags genpts+nobuffer+flush_packets",
209
- //"-rtpflags latm",
210
- ];
211
- switch (metadata.videoCodec) {
212
- case eufy_security_client_1.VideoCodec.H264:
213
- videoFormat = "h264";
214
- break;
215
- case eufy_security_client_1.VideoCodec.H265:
216
- videoFormat = "hevc";
217
- break;
218
- }
219
- switch (metadata.audioCodec) {
220
- case eufy_security_client_1.AudioCodec.AAC:
221
- audioFormat = "aac";
222
- break;
223
- }
224
- const command = (0, fluent_ffmpeg_1.default)()
225
- .withProcessOptions({
226
- detached: true
227
- })
228
- .input(uVideoStream.url)
229
- .inputFormat(videoFormat)
230
- .inputFps(metadata.videoFPS)
231
- .videoCodec("copy");
232
- if (audioFormat !== "") {
233
- command.input(uAudioStream.url)
234
- .inputFormat(audioFormat)
235
- //.audioCodec("copy");
236
- //.audioCodec("aac");
237
- .audioCodec("opus");
238
- }
239
- else {
240
- log.warn(`ffmpegStreamToGo2rtc(): Not support audio codec or unknown audio codec (${eufy_security_client_1.AudioCodec[metadata.audioCodec]})`);
241
- }
242
- command.output(`rtsp://localhost:${config.go2rtc_rtsp_port}/${camera}`)
243
- .outputFormat("rtsp")
244
- .addOptions(options)
245
- .on("error", function (err, stdout, stderr) {
246
- log.error(`ffmpegStreamToGo2rtc(): An error occurred: ${err.message}`);
247
- log.error(`ffmpegStreamToGo2rtc(): ffmpeg output:\n${stdout}`);
248
- log.error(`ffmpegStreamToGo2rtc(): ffmpeg stderr:\n${stderr}`);
249
- uVideoStream.close();
250
- uAudioStream.close();
251
- reject(err);
252
- })
253
- .on("end", () => {
254
- log.debug("ffmpegStreamToGo2rtc(): Processing finished!");
255
- uVideoStream.close();
256
- uAudioStream.close();
257
- resolve();
258
- });
259
- command.run();
260
- }
261
- else {
262
- reject(new Error("ffmpeg binary not found"));
263
- }
182
+ return new Promise((resolve, reject) => {
183
+ try {
184
+ if (import_ffmpeg_static.default) {
185
+ import_fluent_ffmpeg.default.setFfmpegPath(import_ffmpeg_static.default);
186
+ log.warn("ffmpegStreamToGo2rtc(): Started");
187
+ videoStream.on("error", (error) => {
188
+ log.error("ffmpegStreamToGo2rtc(): Videostream Error", error);
189
+ });
190
+ audioStream.on("error", (error) => {
191
+ log.error("ffmpegStreamToGo2rtc(): Audiostream Error", error);
192
+ });
193
+ const uVideoStream = StreamInput(namespace, videoStream);
194
+ const uAudioStream = StreamInput(namespace, audioStream);
195
+ let videoFormat = "h264";
196
+ let audioFormat = "";
197
+ const options = [
198
+ "-rtsp_transport tcp",
199
+ "-sc_threshold 0",
200
+ `-g ${metadata.videoFPS}`,
201
+ "-fflags genpts+nobuffer+flush_packets"
202
+ ];
203
+ switch (metadata.videoCodec) {
204
+ case import_eufy_security_client.VideoCodec.H264:
205
+ videoFormat = "h264";
206
+ break;
207
+ case import_eufy_security_client.VideoCodec.H265:
208
+ videoFormat = "hevc";
209
+ break;
210
+ }
211
+ switch (metadata.audioCodec) {
212
+ case import_eufy_security_client.AudioCodec.AAC:
213
+ audioFormat = "aac";
214
+ break;
264
215
  }
265
- catch (error) {
266
- log.error(`ffmpegStreamToGo2rtc(): Error: ${error}`);
267
- reject(error);
216
+ const command = (0, import_fluent_ffmpeg.default)().withProcessOptions({
217
+ detached: true
218
+ }).input(uVideoStream.url).inputFormat(videoFormat).inputFps(metadata.videoFPS).videoCodec("copy");
219
+ if (audioFormat !== "") {
220
+ command.input(uAudioStream.url).inputFormat(audioFormat).audioCodec("opus");
221
+ } else {
222
+ log.warn(`ffmpegStreamToGo2rtc(): Not support audio codec or unknown audio codec (${import_eufy_security_client.AudioCodec[metadata.audioCodec]})`);
268
223
  }
269
- });
224
+ command.output(`rtsp://localhost:${config.go2rtc_rtsp_port}/${camera}`).outputFormat("rtsp").addOptions(options).on("error", function(err, stdout, stderr) {
225
+ log.error(`ffmpegStreamToGo2rtc(): An error occurred: ${err.message}`);
226
+ log.error(`ffmpegStreamToGo2rtc(): ffmpeg output:
227
+ ${stdout}`);
228
+ log.error(`ffmpegStreamToGo2rtc(): ffmpeg stderr:
229
+ ${stderr}`);
230
+ uVideoStream.close();
231
+ uAudioStream.close();
232
+ reject(err);
233
+ }).on("end", () => {
234
+ log.debug("ffmpegStreamToGo2rtc(): Processing finished!");
235
+ uVideoStream.close();
236
+ uAudioStream.close();
237
+ resolve();
238
+ });
239
+ command.run();
240
+ } else {
241
+ reject(new Error("ffmpeg binary not found"));
242
+ }
243
+ } catch (error) {
244
+ log.error(`ffmpegStreamToGo2rtc(): Error: ${error}`);
245
+ reject(error);
246
+ }
247
+ });
270
248
  };
271
- exports.ffmpegStreamToGo2rtc = ffmpegStreamToGo2rtc;
272
- //# sourceMappingURL=video.js.map
249
+ // Annotate the CommonJS export names for ESM import in node:
250
+ 0 && (module.exports = {
251
+ StreamInput,
252
+ StreamOutput,
253
+ ffmpegPreviewImage,
254
+ ffmpegStreamToGo2rtc,
255
+ ffmpegStreamToHls
256
+ });
257
+ //# sourceMappingURL=video.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"video.js","sourceRoot":"","sources":["../../src/lib/video.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAsB;AACtB,gDAAwB;AACxB,0EAA2C;AAC3C,kEAAyC;AAEzC,+DAA8E;AAC9E,2BAA4B;AAC5B,wDAA2B;AAG3B,mCAA6C;AAE7C,MAAM,eAAe;IAOjB,YAAa,SAAiB,EAAE,QAAoD;QAChF,IAAI,QAAQ,GAAG,EAAE,CAAC;QAElB,MAAM,cAAc,GAAG,IAAA,0BAAkB,EAAC,CAAC,GAAG,eAAe,CAAC,KAAK,CA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AE,CAAC;gBACd,CAAC,CAAC,CAAC;gBACP,OAAO,CAAC,GAAG,EAAE,CAAC;aACjB;iBAAM;gBACH,MAAM,CAAC,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC,CAAC;aAChD;SACJ;QAAC,OAAO,KAAK,EAAE;YACZ,GAAG,CAAC,KAAK,CAAC,kCAAkC,KAAK,EAAE,CAAC,CAAC;YACrD,MAAM,CAAC,KAAK,CAAC,CAAC;SACjB;IACL,CAAC,CAAC,CAAC;AACP,CAAC,CAAA;AA9FY,QAAA,oBAAoB,wBA8FhC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/lib/video.ts"],
4
+ "sourcesContent": ["import net from \"net\";\r\nimport path from \"path\";\r\nimport ffmpeg from \"@bropat/fluent-ffmpeg\";\r\nimport pathToFfmpeg from \"ffmpeg-static\";\r\nimport { Readable } from \"stream\";\r\nimport { StreamMetadata, AudioCodec, VideoCodec } from \"eufy-security-client\";\r\nimport { tmpdir } from \"os\";\r\nimport fse from \"fs-extra\";\r\n\r\nimport { ioBrokerLogger } from \"./log\";\r\nimport { lowestUnusedNumber } from \"./utils\";\r\n\r\nclass UniversalStream {\r\n\r\n public url: string;\r\n private static socks = new Set<number>();\r\n private server: net.Server;\r\n private sock_id: number;\r\n\r\n constructor (namespace: string, onSocket: ((socket: net.Socket) => void) | undefined) {\r\n let sockpath = \"\";\r\n\r\n const unique_sock_id = lowestUnusedNumber([...UniversalStream.socks], 1);\r\n UniversalStream.socks.add(unique_sock_id);\r\n this.sock_id = unique_sock_id;\r\n\r\n if (process.platform === \"win32\") {\r\n const pipePrefix = \"\\\\\\\\.\\\\pipe\\\\\";\r\n const pipeName = `node-webrtc.${namespace}.${unique_sock_id}.sock`;\r\n\r\n sockpath = path.join(pipePrefix, pipeName);\r\n this.url = sockpath;\r\n }\r\n else {\r\n const pipeName = `${namespace}.${unique_sock_id}.sock`;\r\n sockpath = path.join(tmpdir(), pipeName);\r\n this.url = \"unix:\" + sockpath;\r\n\r\n try {\r\n if (fse.existsSync(sockpath))\r\n fse.unlinkSync(sockpath);\r\n } catch(error) {\r\n }\r\n }\r\n\r\n this.server = net.createServer(onSocket);\r\n this.server.listen(sockpath);\r\n }\r\n\r\n public close(): void {\r\n if (this.server)\r\n this.server.close();\r\n UniversalStream.socks.delete(this.sock_id);\r\n }\r\n\r\n}\r\n\r\nexport const StreamInput = function(namespace: string, stream: NodeJS.ReadableStream): UniversalStream {\r\n return new UniversalStream(namespace, (socket: net.Socket) => stream.pipe(socket, { end: true }))\r\n}\r\n\r\nexport const StreamOutput = function(namespace: string, stream: NodeJS.WritableStream): UniversalStream {\r\n return new UniversalStream(namespace, (socket: net.Socket) => socket.pipe(stream, { end: true }))\r\n}\r\n\r\nexport const ffmpegPreviewImage = (config: ioBroker.AdapterConfig, input:string, output: string, log: ioBrokerLogger, skip_seconds = 2.0): Promise<void> => {\r\n return new Promise((resolve, reject) => {\r\n try {\r\n if (pathToFfmpeg) {\r\n ffmpeg.setFfmpegPath(pathToFfmpeg);\r\n\r\n ffmpeg()\r\n .withProcessOptions({\r\n detached: true\r\n })\r\n .addOptions([\r\n `-ss ${skip_seconds}`,\r\n \"-frames:v 1\"\r\n ])\r\n .input(input)\r\n .inputFormat(\"hls\")\r\n .outputFormat(\"image2\")\r\n .output(output)\r\n .on(\"error\", function(err, stdout, stderr) {\r\n log.error(`ffmpegPreviewImage(): An error occurred: ${err.message}`);\r\n log.error(`ffmpegPreviewImage(): ffmpeg output:\\n${stdout}`);\r\n log.error(`ffmpegPreviewImage(): ffmpeg stderr:\\n${stderr}`);\r\n reject(err);\r\n })\r\n .on(\"end\", () => {\r\n log.debug(\"ffmpegPreviewImage(): Preview image generated!\");\r\n resolve();\r\n })\r\n .run();\r\n } else {\r\n reject(new Error(\"ffmpeg binary not found\"));\r\n }\r\n } catch (error) {\r\n log.error(`ffmpegPreviewImage(): Error: ${error}`);\r\n reject(error);\r\n }\r\n });\r\n}\r\n\r\nexport const ffmpegStreamToHls = (config: ioBroker.AdapterConfig, namespace: string, metadata: StreamMetadata, videoStream: Readable, audioStream: Readable, output: string, log: ioBrokerLogger): Promise<void> => {\r\n return new Promise((resolve, reject) => {\r\n try {\r\n if (pathToFfmpeg) {\r\n ffmpeg.setFfmpegPath(pathToFfmpeg);\r\n\r\n videoStream.on(\"error\", (error) => {\r\n log.error(\"ffmpegStreamToHls(): Videostream Error\", error);\r\n });\r\n\r\n audioStream.on(\"error\", (error) => {\r\n log.error(\"ffmpegStreamToHls(): Audiostream Error\", error);\r\n });\r\n\r\n const uVideoStream = StreamInput(namespace, videoStream);\r\n const uAudioStream = StreamInput(namespace, audioStream);\r\n\r\n let videoFormat = \"h264\";\r\n let audioFormat = \"\";\r\n const options: string[] = [\r\n \"-hls_init_time 0\",\r\n \"-hls_time 2\",\r\n \"-hls_segment_type mpegts\",\r\n //\"-start_number 1\",\r\n \"-sc_threshold 0\",\r\n `-g ${metadata.videoFPS}`,\r\n \"-fflags genpts+nobuffer+flush_packets\",\r\n //\"-flush_packets 1\",\r\n \"-hls_playlist_type event\"\r\n //\"-hls_flags split_by_time\"\r\n ];\r\n\r\n switch(metadata.videoCodec) {\r\n case VideoCodec.H264:\r\n videoFormat = \"h264\";\r\n break;\r\n case VideoCodec.H265:\r\n videoFormat = \"hevc\";\r\n break;\r\n }\r\n\r\n switch(metadata.audioCodec) {\r\n case AudioCodec.AAC:\r\n audioFormat = \"aac\";\r\n break;\r\n }\r\n\r\n const command = ffmpeg()\r\n .withProcessOptions({\r\n detached: true\r\n })\r\n .input(uVideoStream.url)\r\n .inputFormat(videoFormat)\r\n .inputFps(metadata.videoFPS);\r\n if (audioFormat !== \"\") {\r\n command.input(uAudioStream.url)\r\n .inputFormat(audioFormat)\r\n .videoCodec(\"copy\")\r\n .audioCodec(\"copy\");\r\n options.push(\"-absf aac_adtstoasc\");\r\n } else {\r\n log.warn(`ffmpegStreamToHls(): Not support audio codec or unknown audio codec (${AudioCodec[metadata.audioCodec]})`);\r\n }\r\n command.output(output)\r\n .addOptions(options)\r\n .on(\"error\", function(err, stdout, stderr) {\r\n log.error(`ffmpegStreamToHls(): An error occurred: ${err.message}`);\r\n log.error(`ffmpegStreamToHls(): ffmpeg output:\\n${stdout}`);\r\n log.error(`ffmpegStreamToHls(): ffmpeg stderr:\\n${stderr}`);\r\n uVideoStream.close();\r\n uAudioStream.close();\r\n reject(err);\r\n })\r\n .on(\"end\", () => {\r\n log.debug(\"ffmpegStreamToHls(): Processing finished!\");\r\n uVideoStream.close();\r\n uAudioStream.close();\r\n resolve();\r\n });\r\n command.run();\r\n } else {\r\n reject(new Error(\"ffmpeg binary not found\"));\r\n }\r\n } catch (error) {\r\n log.error(`ffmpegStreamToHls(): Error: ${error}`);\r\n reject(error);\r\n }\r\n });\r\n}\r\n\r\nexport const ffmpegStreamToGo2rtc = (config: ioBroker.AdapterConfig, namespace: string, camera: string, metadata: StreamMetadata, videoStream: Readable, audioStream: Readable, log: ioBrokerLogger): Promise<void> => {\r\n return new Promise((resolve, reject) => {\r\n try {\r\n if (pathToFfmpeg) {\r\n ffmpeg.setFfmpegPath(pathToFfmpeg);\r\n\r\n log.warn(\"ffmpegStreamToGo2rtc(): Started\");\r\n\r\n videoStream.on(\"error\", (error) => {\r\n log.error(\"ffmpegStreamToGo2rtc(): Videostream Error\", error);\r\n });\r\n\r\n audioStream.on(\"error\", (error) => {\r\n log.error(\"ffmpegStreamToGo2rtc(): Audiostream Error\", error);\r\n });\r\n\r\n //TODO: For debugging purposes\r\n /*const outputFile = path.resolve(__dirname, \"../../test-stream.dump\");\r\n videoStream.pipe(fse.createWriteStream(outputFile)).on(\"finish\", () => {\r\n log.debug(\"videoStream dump finished!\");\r\n log.info(\"Manually test the output by running# ffplay output/test-stream.dump\");\r\n });*/\r\n\r\n const uVideoStream = StreamInput(namespace, videoStream);\r\n const uAudioStream = StreamInput(namespace, audioStream);\r\n\r\n let videoFormat = \"h264\";\r\n let audioFormat = \"\";\r\n const options: string[] = [\r\n \"-rtsp_transport tcp\",\r\n \"-sc_threshold 0\",\r\n `-g ${metadata.videoFPS}`,\r\n \"-fflags genpts+nobuffer+flush_packets\",\r\n //\"-rtpflags latm\",\r\n ];\r\n\r\n switch(metadata.videoCodec) {\r\n case VideoCodec.H264:\r\n videoFormat = \"h264\";\r\n break;\r\n case VideoCodec.H265:\r\n videoFormat = \"hevc\";\r\n break;\r\n }\r\n\r\n switch(metadata.audioCodec) {\r\n case AudioCodec.AAC:\r\n audioFormat = \"aac\";\r\n break;\r\n }\r\n\r\n const command = ffmpeg()\r\n .withProcessOptions({\r\n detached: true\r\n })\r\n .input(uVideoStream.url)\r\n .inputFormat(videoFormat)\r\n .inputFps(metadata.videoFPS)\r\n .videoCodec(\"copy\");\r\n if (audioFormat !== \"\") {\r\n command.input(uAudioStream.url)\r\n .inputFormat(audioFormat)\r\n //.audioCodec(\"copy\");\r\n //.audioCodec(\"aac\");\r\n .audioCodec(\"opus\");\r\n } else {\r\n log.warn(`ffmpegStreamToGo2rtc(): Not support audio codec or unknown audio codec (${AudioCodec[metadata.audioCodec]})`);\r\n }\r\n command.output(`rtsp://localhost:${config.go2rtc_rtsp_port}/${camera}`)\r\n .outputFormat(\"rtsp\")\r\n .addOptions(options)\r\n .on(\"error\", function(err, stdout, stderr) {\r\n log.error(`ffmpegStreamToGo2rtc(): An error occurred: ${err.message}`);\r\n log.error(`ffmpegStreamToGo2rtc(): ffmpeg output:\\n${stdout}`);\r\n log.error(`ffmpegStreamToGo2rtc(): ffmpeg stderr:\\n${stderr}`);\r\n uVideoStream.close();\r\n uAudioStream.close();\r\n reject(err);\r\n })\r\n .on(\"end\", () => {\r\n log.debug(\"ffmpegStreamToGo2rtc(): Processing finished!\");\r\n uVideoStream.close();\r\n uAudioStream.close();\r\n resolve();\r\n });\r\n command.run();\r\n } else {\r\n reject(new Error(\"ffmpeg binary not found\"));\r\n }\r\n } catch (error) {\r\n log.error(`ffmpegStreamToGo2rtc(): Error: ${error}`);\r\n reject(error);\r\n }\r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