@eluvio/elv-client-js 4.0.55 → 4.0.57

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.
@@ -0,0 +1,330 @@
1
+ var _classCallCheck = require("@babel/runtime/helpers/classCallCheck");
2
+ var _createClass = require("@babel/runtime/helpers/createClass");
3
+ var LadderTemplate = {
4
+ "2160": {
5
+ bit_rate: 14000000,
6
+ codecs: "avc1.640028,mp4a.40.2",
7
+ height: 2160,
8
+ media_type: 1,
9
+ representation: "videovideo_3840x2160_h264@14000000",
10
+ stream_name: "video",
11
+ width: 3840
12
+ },
13
+ "1080": {
14
+ bit_rate: 9500000,
15
+ codecs: "avc1.640028,mp4a.40.2",
16
+ height: 1080,
17
+ media_type: 1,
18
+ representation: "videovideo_1920x1080_h264@9500000",
19
+ stream_name: "video",
20
+ width: 1920
21
+ },
22
+ "720": {
23
+ bit_rate: 4500000,
24
+ codecs: "avc1.640028,mp4a.40.2",
25
+ height: 720,
26
+ media_type: 1,
27
+ representation: "videovideo_1280x720_h264@4500000",
28
+ stream_name: "video",
29
+ width: 1280
30
+ },
31
+ "540": {
32
+ bit_rate: 2000000,
33
+ codecs: "avc1.640028,mp4a.40.2",
34
+ height: 540,
35
+ media_type: 1,
36
+ representation: "videovideo_960x540_h264@2000000",
37
+ stream_name: "video",
38
+ width: 960
39
+ },
40
+ "360": {
41
+ bit_rate: 520000,
42
+ codecs: "avc1.640028,mp4a.40.2",
43
+ height: 360,
44
+ media_type: 1,
45
+ representation: "videovideo_640x360_h264@520000",
46
+ stream_name: "video",
47
+ width: 640
48
+ }
49
+ };
50
+ var LiveconfTemplate = {
51
+ live_recording: {
52
+ fabric_config: {
53
+ ingress_node_api: "",
54
+ ingress_node_id: ""
55
+ },
56
+ playout_config: {
57
+ rebroadcast_start_time_sec_epoch: 0,
58
+ vod_enabled: false
59
+ },
60
+ recording_config: {
61
+ recording_params: {
62
+ description: "",
63
+ ladder_specs: [{
64
+ bit_rate: 384000,
65
+ channels: 2,
66
+ codecs: "mp4a.40.2",
67
+ media_type: 2,
68
+ representation: "audioaudio_aac@384000",
69
+ stream_name: "audio"
70
+ }],
71
+ listen: true,
72
+ live_delay_nano: 2000000000,
73
+ max_duration_sec: -1,
74
+ name: "",
75
+ origin_url: "",
76
+ part_ttl: 3600,
77
+ playout_type: "live",
78
+ source_timescale: null,
79
+ xc_params: {
80
+ audio_bitrate: 384000,
81
+ audio_index: [0, 0, 0, 0, 0, 0, 0, 0],
82
+ audio_seg_duration_ts: null,
83
+ ecodec2: "aac",
84
+ enc_height: null,
85
+ enc_width: null,
86
+ filter_descriptor: "",
87
+ force_keyint: null,
88
+ format: "fmp4-segment",
89
+ listen: true,
90
+ n_audio: 1,
91
+ preset: "faster",
92
+ sample_rate: 48000,
93
+ seg_duration: null,
94
+ skip_decoding: false,
95
+ start_segment_str: "1",
96
+ stream_id: -1,
97
+ sync_audio_to_stream_id: -1,
98
+ video_bitrate: null,
99
+ video_seg_duration_ts: null,
100
+ xc_type: 3
101
+ }
102
+ }
103
+ }
104
+ }
105
+ };
106
+ var LiveConf = /*#__PURE__*/function () {
107
+ "use strict";
108
+
109
+ function LiveConf(probeData, nodeId, nodeUrl, includeAVSegDurations, overwriteOriginUrl, syncAudioToVideo) {
110
+ _classCallCheck(this, LiveConf);
111
+ this.probeData = probeData;
112
+ this.nodeId = nodeId;
113
+ this.nodeUrl = nodeUrl;
114
+ this.includeAVSegDurations = includeAVSegDurations;
115
+ this.overwriteOriginUrl = overwriteOriginUrl;
116
+ this.syncAudioToVideo = syncAudioToVideo;
117
+ }
118
+ _createClass(LiveConf, [{
119
+ key: "probeKind",
120
+ value: function probeKind() {
121
+ var fileNameSplit = this.probeData.format.filename.split(":");
122
+ return fileNameSplit[0];
123
+ }
124
+ }, {
125
+ key: "getStreamDataForCodecType",
126
+ value: function getStreamDataForCodecType(codecType) {
127
+ var stream = null;
128
+ for (var index = 0; index < this.probeData.streams.length; index++) {
129
+ if (this.probeData.streams[index].codec_type == codecType) {
130
+ stream = this.probeData.streams[index];
131
+ }
132
+ }
133
+ return stream;
134
+ }
135
+ }, {
136
+ key: "getFrameRate",
137
+ value: function getFrameRate() {
138
+ var videoStream = this.getStreamDataForCodecType("video");
139
+ var frameRate = videoStream.r_frame_rate || videoStream.frame_rate;
140
+ return frameRate.split("/");
141
+ }
142
+ }, {
143
+ key: "isFrameRateWhole",
144
+ value: function isFrameRateWhole() {
145
+ var frameRate = this.getFrameRate();
146
+ return frameRate[1] == "1";
147
+ }
148
+ }, {
149
+ key: "getForceKeyint",
150
+ value: function getForceKeyint() {
151
+ var frameRate = this.getFrameRate();
152
+ var roundedFrameRate = Math.round(frameRate[0] / frameRate[1]);
153
+ if (roundedFrameRate > 30) {
154
+ return roundedFrameRate;
155
+ } else {
156
+ return roundedFrameRate * 2;
157
+ }
158
+ }
159
+ }, {
160
+ key: "calcSegDuration",
161
+ value: function calcSegDuration(_ref) {
162
+ var sourceTimescale = _ref.sourceTimescale;
163
+ var videoStream = this.getStreamDataForCodecType("video");
164
+ var frameRate = videoStream.frame_rate;
165
+ var seg = {};
166
+ switch (frameRate) {
167
+ case "24":
168
+ seg.video = 30 * sourceTimescale;
169
+ seg.audio = 30 * 48000;
170
+ seg.keyint = 48;
171
+ seg.duration = "30";
172
+ break;
173
+ case "25":
174
+ seg.video = 30 * sourceTimescale;
175
+ seg.audio = 30 * 48000;
176
+ seg.keyint = 50;
177
+ seg.duration = "30";
178
+ break;
179
+ case "30":
180
+ seg.video = 30 * sourceTimescale;
181
+ seg.audio = 30 * 48000;
182
+ seg.keyint = 60;
183
+ seg.duration = "30";
184
+ break;
185
+ case "30000/1001":
186
+ seg.video = 30.03 * sourceTimescale;
187
+ seg.audio = 29.76 * 48000;
188
+ seg.keyint = 60;
189
+ seg.duration = "30.03";
190
+ break;
191
+ case "48":
192
+ seg.video = 30 * sourceTimescale;
193
+ seg.audio = 30 * 48000;
194
+ seg.keyint = 96;
195
+ seg.duration = "30";
196
+ break;
197
+ case "50":
198
+ seg.video = 30 * sourceTimescale;
199
+ seg.audio = 30 * 48000;
200
+ seg.keyint = 100;
201
+ seg.duration = "30";
202
+ break;
203
+ case "60":
204
+ seg.video = 30 * sourceTimescale;
205
+ seg.audio = 30 * 48000;
206
+ seg.keyint = 120;
207
+ seg.duration = "30";
208
+ break;
209
+ case "60000/1001":
210
+ seg.video = 30.03 * sourceTimescale;
211
+ seg.audio = 29.76 * 48000;
212
+ seg.keyint = 120;
213
+ seg.duration = "30.03";
214
+ break;
215
+ default:
216
+ console.log("Unsupported frame rate", frameRate);
217
+ break;
218
+ }
219
+ return seg;
220
+ }
221
+ }, {
222
+ key: "syncAudioToStreamIdValue",
223
+ value: function syncAudioToStreamIdValue() {
224
+ var sync_id = -1;
225
+ var videoStream = this.getStreamDataForCodecType("video");
226
+ switch (this.probeKind()) {
227
+ case "udp":
228
+ sync_id = videoStream.stream_id;
229
+ break;
230
+ case "rtmp":
231
+ sync_id = -1; // Pending fabric API: videoStream.stream_index
232
+ break;
233
+ }
234
+ return sync_id;
235
+ }
236
+ }, {
237
+ key: "generateLiveConf",
238
+ value: function generateLiveConf() {
239
+ // gather required data
240
+ var conf = LiveconfTemplate;
241
+ var fileName = this.overwriteOriginUrl || this.probeData.format.filename;
242
+ var audioStream = this.getStreamDataForCodecType("audio");
243
+ var sampleRate = parseInt(audioStream.sample_rate);
244
+ var videoStream = this.getStreamDataForCodecType("video");
245
+ var sourceTimescale;
246
+ console.log("AUDIO", audioStream);
247
+ console.log("VIDEO", videoStream);
248
+
249
+ // Fill in liveconf all formats have in common
250
+ conf.live_recording.fabric_config.ingress_node_api = this.nodeUrl || null;
251
+ conf.live_recording.fabric_config.ingress_node_id = this.nodeId || null;
252
+ conf.live_recording.recording_config.recording_params.description;
253
+ conf.live_recording.recording_config.recording_params.origin_url = fileName;
254
+ conf.live_recording.recording_config.recording_params.description = "Ingest stream ".concat(fileName);
255
+ conf.live_recording.recording_config.recording_params.name = "Ingest stream ".concat(fileName);
256
+ conf.live_recording.recording_config.recording_params.xc_params.audio_index[0] = audioStream.stream_index;
257
+ conf.live_recording.recording_config.recording_params.xc_params.sample_rate = sampleRate;
258
+ conf.live_recording.recording_config.recording_params.xc_params.enc_height = videoStream.height;
259
+ conf.live_recording.recording_config.recording_params.xc_params.enc_width = videoStream.width;
260
+ if (this.syncAudioToVideo) {
261
+ conf.live_recording.recording_config.recording_params.xc_params.sync_audio_to_stream_id = this.syncAudioToStreamIdValue();
262
+ }
263
+
264
+ // Fill in specifics for protocol
265
+ switch (this.probeKind()) {
266
+ case "udp":
267
+ sourceTimescale = 90000;
268
+ conf.live_recording.recording_config.recording_params.source_timescale = sourceTimescale;
269
+ break;
270
+ case "rtmp":
271
+ sourceTimescale = 16000;
272
+ conf.live_recording.recording_config.recording_params.source_timescale = sourceTimescale;
273
+ break;
274
+ case "hls":
275
+ console.log("HLS detected. Not yet implemented");
276
+ break;
277
+ default:
278
+ console.log("Unsuppoted media", this.probeKind());
279
+ break;
280
+ }
281
+ var segDurations = this.calcSegDuration({
282
+ sourceTimescale: sourceTimescale
283
+ });
284
+
285
+ // Segment conditioning parameters
286
+ conf.live_recording.recording_config.recording_params.xc_params.seg_duration = segDurations.duration;
287
+ conf.live_recording.recording_config.recording_params.xc_params.audio_seg_duration_ts = segDurations.audio;
288
+ conf.live_recording.recording_config.recording_params.xc_params.video_seg_duration_ts = segDurations.video;
289
+ conf.live_recording.recording_config.recording_params.xc_params.force_keyint = segDurations.keyint;
290
+ switch (videoStream.height) {
291
+ case 2160:
292
+ conf.live_recording.recording_config.recording_params.ladder_specs.unshift(LadderTemplate[2160], LadderTemplate[1080], LadderTemplate[720], LadderTemplate[540], LadderTemplate[360]);
293
+ conf.live_recording.recording_config.recording_params.xc_params.video_bitrate = LadderTemplate[2160].bit_rate;
294
+ conf.live_recording.recording_config.recording_params.xc_params.enc_height = 2160;
295
+ conf.live_recording.recording_config.recording_params.xc_params.enc_width = 3840;
296
+ break;
297
+ case 1080:
298
+ conf.live_recording.recording_config.recording_params.ladder_specs.unshift(LadderTemplate[1080], LadderTemplate[720], LadderTemplate[540], LadderTemplate[360]);
299
+ conf.live_recording.recording_config.recording_params.xc_params.video_bitrate = LadderTemplate[1080].bit_rate;
300
+ conf.live_recording.recording_config.recording_params.xc_params.enc_height = 1080;
301
+ conf.live_recording.recording_config.recording_params.xc_params.enc_width = 1920;
302
+ break;
303
+ case 720:
304
+ conf.live_recording.recording_config.recording_params.ladder_specs.unshift(LadderTemplate[720], LadderTemplate[540], LadderTemplate[360]);
305
+ conf.live_recording.recording_config.recording_params.xc_params.video_bitrate = LadderTemplate[720].bit_rate;
306
+ conf.live_recording.recording_config.recording_params.xc_params.enc_height = 720;
307
+ conf.live_recording.recording_config.recording_params.xc_params.enc_width = 1280;
308
+ break;
309
+ case 540:
310
+ conf.live_recording.recording_config.recording_params.ladder_specs.unshift(LadderTemplate[540], LadderTemplate[360]);
311
+ conf.live_recording.recording_config.recording_params.xc_params.video_bitrate = LadderTemplate[540].bit_rate;
312
+ conf.live_recording.recording_config.recording_params.xc_params.enc_height = 540;
313
+ conf.live_recording.recording_config.recording_params.xc_params.enc_width = 960;
314
+ break;
315
+ case 360:
316
+ conf.live_recording.recording_config.recording_params.ladder_specs.unshift(LadderTemplate[360]);
317
+ conf.live_recording.recording_config.recording_params.ladder_specs.unshift(LadderTemplate[360]);
318
+ conf.live_recording.recording_config.recording_params.xc_params.video_bitrate = LadderTemplate[360].bit_rate;
319
+ conf.live_recording.recording_config.recording_params.xc_params.enc_height = 360;
320
+ conf.live_recording.recording_config.recording_params.xc_params.enc_width = 640;
321
+ break;
322
+ default:
323
+ throw new Error("ERROR: Probed stream does not conform to one of the following built in resolution ladders [4096, 2160], [1920, 1080] [1280, 720], [960, 540], [640, 360]");
324
+ }
325
+ return JSON.stringify(conf, null, 2);
326
+ }
327
+ }]);
328
+ return LiveConf;
329
+ }();
330
+ exports.LiveConf = LiveConf;